예제 #1
0
        public void Start(ParameterDelegate method, object parameter)
        {
            SynchronizationContext context = SynchronizationContext.Current;

            // if there is no synchronization, don't launch a new thread
            if ( context != null )
            {
                // new thread to execute the Load() method for the layer
                new Thread( ( object args ) =>
                {
                    method.DynamicInvoke( args );

                    //// fire the OnLoadComplete event on the original thread
                    //context.Post( new SendOrPostCallback( ( obj ) =>
                    //{
                    //    add callback method call here if needed in future
                    //} ), null );

                } ).Start( parameter );
            }
            else
            {
                method.DynamicInvoke( parameter );
            }
        }
        protected override void OnParameterLoad(ConfigNode node)
        {
            monolithDiscovered = ConfigNodeUtil.ParseValue <bool>(node, "monolithDiscovered");
            currentState       = ConfigNodeUtil.ParseValue <MonolithState>(node, "currentState");
            starJeb            = ConfigNodeUtil.ParseValue <Vessel>(node, "starJeb", (Vessel)null);
            candidate          = ConfigNodeUtil.ParseValue <Vessel>(node, "candidate", starJeb);
            starJebName        = ConfigNodeUtil.ParseValue <string>(node, "starJebName", "");
            candidateName      = ConfigNodeUtil.ParseValue <string>(node, "candidateName", "");
            if (node.HasValue("velocity.x"))
            {
                float x = ConfigNodeUtil.ParseValue <float>(node, "velocity.x");
                float y = ConfigNodeUtil.ParseValue <float>(node, "velocity.y");
                float z = ConfigNodeUtil.ParseValue <float>(node, "velocity.z");
                velocity = new Vector3(x, y, z);
            }
            if (node.HasNode("PROGRESS_TREE_BACKUP"))
            {
                progressTreeBackup = node.GetNode("PROGRESS_TREE_BACKUP");
            }

            stepTime = Time.fixedTime;

            ParameterDelegate <string> .OnDelegateContainerLoad(node);

            CreateDelegates();
        }
 protected override void OnParameterLoad(ConfigNode node)
 {
     try
     {
         field         = ConfigNodeUtil.ParseValue <RadiationFieldType>(node, "field", RadiationFieldType.UNDEFINED);
         targetBody    = ConfigNodeUtil.ParseValue <CelestialBody>(node, "targetBody", (CelestialBody)null);
         crossings_min = ConfigNodeUtil.ParseValue <int>(node, "crossings_min", 0);
         crossings_max = ConfigNodeUtil.ParseValue <int>(node, "crossings_max", 0);
         title         = ConfigNodeUtil.ParseValue(node, "title", string.Empty);
     }
     finally
     {
         ParameterDelegate <Vessel> .OnDelegateContainerLoad(node);
     }
 }
예제 #4
0
        protected override void OnParameterLoad(ConfigNode node)
        {
            base.OnParameterLoad(node);
            minRange     = ConfigNodeUtil.ParseValue <double>(node, "minRange");
            maxRange     = ConfigNodeUtil.ParseValue <double>(node, "maxRange", double.MaxValue);
            targetBody   = ConfigNodeUtil.ParseValue <CelestialBody>(node, "targetBody", (CelestialBody)null);
            activeVessel = ConfigNodeUtil.ParseValue <bool>(node, "activeVessel");
            minCount     = ConfigNodeUtil.ParseValue <int>(node, "minCount");
            maxCount     = ConfigNodeUtil.ParseValue <int>(node, "maxCount");
            antennaType  = ConfigNodeUtil.ParseValue <AntennaType?>(node, "antennaType", (AntennaType?)null);

            ParameterDelegate <IAntenna> .OnDelegateContainerLoad(node);

            CreateDelegates();
        }
예제 #5
0
        /// <summary>
        /// Starts a new thread invoking the specified method with the parameter provided.
        /// </summary>
        /// <param name="method">The method to invoke.</param>
        /// <param name="parameter">The method parameter.</param>
        public void Start(ParameterDelegate method, object parameter)
        {
            SynchronizationContext context = SynchronizationContext.Current;

            // if there is no synchronization, don't launch a new thread
            if (context != null)
            {
                // new thread to execute the Load() method for the layer
                new Thread(() => method.DynamicInvoke(parameter)).Start();
            }
            else
            {
                method.DynamicInvoke(parameter);
            }
        }
        protected void CreateDelegates()
        {
            if (ParameterCount < 1)
            {
                LoggingUtil.LogDebug(this, "Adding EVA parameter...");
                evaParam = new ParameterDelegate <MonolithParameter>("Send a Kerbal on EVA", x => CheckParameters(MonolithState.STARTED));
                AddParameter(evaParam);

                LoggingUtil.LogDebug(this, "Adding approach parameter...");
                approachParam        = new ParameterDelegate <MonolithParameter>("", x => !approachParam.hidden && CheckParameters(MonolithState.EVA));
                approachParam.hidden = true;
                AddParameter(approachParam);

                LoggingUtil.LogDebug(this, "Adding 'full of stars' parameter...");
                fullofstarsParam        = new ParameterDelegate <MonolithParameter>("...it's full of stars!", x => !fullofstarsParam.hidden && CheckParameters(MonolithState.FULL_OF_STARS_FINAL));
                fullofstarsParam.hidden = true;
                AddParameter(fullofstarsParam);
            }

            bool changeMade = false;

            if (currentState >= MonolithState.EVA)
            {
                if (approachParam.hidden)
                {
                    LoggingUtil.LogDebug(this, "Unhiding approach parameter...");
                    approachParam.SetTitle("Approach the monolith with " + candidateName);
                    changeMade           = true;
                    approachParam.hidden = false;
                }
            }

            if (currentState >= MonolithState.FULL_OF_STARS1)
            {
                if (fullofstarsParam.hidden)
                {
                    LoggingUtil.LogDebug(this, "Unhiding 'full of stars' parameter...");
                    changeMade = true;
                    fullofstarsParam.hidden = false;
                }
            }

            if (changeMade)
            {
                ContractConfigurator.ContractConfigurator.OnParameterChange.Fire(Root, this);
            }
        }
        protected override void OnUpdate()
        {
            base.OnUpdate();

            if (monolith == null && (HighLogic.LoadedScene == GameScenes.FLIGHT || HighLogic.LoadedScene == GameScenes.TRACKSTATION))
            {
                monolith = ContractVesselTracker.Instance.GetAssociatedVessel("Monolith");
                if (monolith != null)
                {
                    monolith.vesselRanges.orbit.load   = MONOLITH_DRAW_DISTANCE * 1.05f;
                    monolith.vesselRanges.orbit.unload = MONOLITH_DRAW_DISTANCE * 1.1f;

                    // Set monolith name to unknown
                    if (!monolithDiscovered && monolith.vesselName != "???")
                    {
                        monolith.vesselName = "???";
                        GameEvents.onVesselRename.Fire(new GameEvents.HostedFromToAction <Vessel, string>(monolith, "Monolith", "???"));
                    }
                }
            }

            if (HighLogic.LoadedScene == GameScenes.FLIGHT && FlightGlobals.ActiveVessel != null)
            {
                // Set the load distance for the monolith to be much further
                SetLoadDistance();

                // Check our script progress
                ParameterDelegate <MonolithParameter> .CheckChildConditions(this, this);

                if (ChildChanged)
                {
                    ContractConfigurator.ContractConfigurator.OnParameterChange.Fire(Root, this);
                    ChildChanged = false;
                }

                if (currentState == MonolithState.FINISHED)
                {
                    // Reset the state of the progress tree
                    ProgressTracking.Instance.OnLoad(progressTreeBackup);

                    // Complete the parameter
                    SetState(ParameterState.Complete);
                }
            }
        }
예제 #8
0
        /// <summary>
        /// Whether this vessel meets the parameter condition.
        /// </summary>
        /// <param name="vessel">Vessel to check</param>
        /// <returns>Whether the vessel meets the parameter condition(s).</returns>
        protected override bool VesselMeetsCondition(Vessel vessel)
        {
            LoggingUtil.LogVerbose(this, "Checking VesselMeetsCondition: " + vessel.id);

            // Get all the antennae
            VesselSatellite        sat      = RTCore.Instance.Satellites[vessel.id];
            IEnumerable <IAntenna> antennas = sat != null ? sat.Antennas : new List <IAntenna>();

            // If we're a VesselParameterGroup child, only do actual state change if we're the tracked vessel
            bool checkOnly = false;

            if (Parent is VesselParameterGroup)
            {
                checkOnly = ((VesselParameterGroup)Parent).TrackedVessel != vessel;
            }

            return(ParameterDelegate <IAntenna> .CheckChildConditions(this, antennas, checkOnly));
        }
예제 #9
0
        protected override string GetParameterTitle()
        {
            string output = null;

            if (string.IsNullOrEmpty(title))
            {
                output = "Antenna";
                if (state == ParameterState.Complete)
                {
                    output += ": " + ParameterDelegate <IAntenna> .GetDelegateText(this);
                }
            }
            else
            {
                output = title;
            }
            return(output);
        }
예제 #10
0
        public Parameter(string aName, Expression expression)
        {
            _Value = 0;

            var parts = aName.Split('.');

            if (parts.Length == 1)
            {
                _NameSpace = string.Empty;
                _Parameter = parts[0].ToUpper();
            }
            else if (parts.Length == 2)
            {
                _NameSpace = parts[0].ToUpper();
                _Parameter = parts[1].ToUpper();
                _Func      = expression.GetContextValue;
            }
            else
            {
                throw new ParseException("Invalid Parameter");
            }
        }
예제 #11
0
        protected override string GetParameterTitle()
        {
            string output = null;

            if (string.IsNullOrEmpty(title))
            {
                if (state == ParameterState.Complete || ParameterCount == 1)
                {
                    if (ParameterCount == 1)
                    {
                        hideChildren = true;
                    }

                    output = ParameterDelegate <Vessel> .GetDelegateText(this);
                }
            }
            else
            {
                output = title;
            }
            return(output);
        }
예제 #12
0
        protected override void OnParameterLoad(ConfigNode node)
        {
            try
            {
                base.OnParameterLoad(node);

                capacity = ConfigNodeUtil.ParseValue <bool?>(node, "capacity", (bool?)false).Value;

                foreach (ConfigNode childNode in node.GetNodes("RESOURCE"))
                {
                    HasResource.Filter filter = new HasResource.Filter();

                    filter.resource    = ConfigNodeUtil.ParseValue <PartResourceDefinition>(childNode, "resource");
                    filter.minQuantity = ConfigNodeUtil.ParseValue <double>(childNode, "minQuantity");
                    filter.maxQuantity = ConfigNodeUtil.ParseValue <double>(childNode, "maxQuantity", double.MaxValue);

                    filters.Add(filter);
                }

                // Legacy
                if (node.HasValue("resource"))
                {
                    HasResource.Filter filter = new HasResource.Filter();

                    filter.resource    = ConfigNodeUtil.ParseValue <PartResourceDefinition>(node, "resource");
                    filter.minQuantity = ConfigNodeUtil.ParseValue <double>(node, "minQuantity");
                    filter.maxQuantity = ConfigNodeUtil.ParseValue <double>(node, "maxQuantity", double.MaxValue);

                    filters.Add(filter);
                }

                CreateDelegates();
            }
            finally
            {
                ParameterDelegate <Part> .OnDelegateContainerLoad(node);
            }
        }
예제 #13
0
        public void Start(ParameterDelegate method, object parameter)
        {
            SynchronizationContext context = SynchronizationContext.Current;

            // if there is no synchronization, don't launch a new thread
            if (context != null)
            {
                // new thread to execute the Load() method for the layer
                new Thread(( object args ) =>
                {
                    method.DynamicInvoke(args);

                    //// fire the OnLoadComplete event on the original thread
                    //context.Post( new SendOrPostCallback( ( obj ) =>
                    //{
                    //    add callback method call here if needed in future
                    //} ), null );
                }).Start(parameter);
            }
            else
            {
                method.DynamicInvoke(parameter);
            }
        }
예제 #14
0
 /// <summary>
 /// Starts a new thread invoking the specified method with the parameter provided.
 /// </summary>
 /// <param name="method">The method to invoke.</param>
 /// <param name="parameter">The method parameter.</param>
 public void Start(ParameterDelegate method, object parameter)
 {
 }
예제 #15
0
        /// <summary>
        /// Whether this vessel meets the parameter condition.
        /// </summary>
        /// <param name="vessel">The vessel to check</param>
        /// <returns>Whether the vessel meets the condition</returns>
        protected override bool VesselMeetsCondition(Vessel vessel)
        {
            LoggingUtil.LogVerbose(this, "Checking VesselMeetsCondition: " + vessel.id);

            return(ParameterDelegate <Vessel> .CheckChildConditions(this, vessel));
        }
예제 #16
0
 public void Start(ParameterDelegate method, object parameter)
 {
     Task.Factory.StartNew(() => method(parameter), TaskCreationOptions.LongRunning);
 }
예제 #17
0
 public void QueueWorker(ParameterDelegate method, object parameter) { }
예제 #18
0
 public void QueueWorker(ParameterDelegate method)
 {
     Task.Factory.StartNew(() => method(null));
 }
예제 #19
0
 public void Start(ParameterDelegate method, object parameter) { }
예제 #20
0
 public void QueueWorker(ParameterDelegate method) { }
예제 #21
0
 public void QueueWorker(ParameterDelegate method, object parameter)
 {
     ThreadPool.QueueUserWorkItem(new WaitCallback(method), parameter);
 }
예제 #22
0
 public void QueueWorker(ParameterDelegate method, object parameter)
 {
     Task.Factory.StartNew(() => method(parameter));
 }
예제 #23
0
 public void Start(ParameterDelegate method, object parameter) { method.DynamicInvoke(parameter); }
예제 #24
0
 public void QueueWorker(ParameterDelegate method) { method.DynamicInvoke(); }
예제 #25
0
 public void QueueWorker(ParameterDelegate method, object parameter) { method.DynamicInvoke(parameter); }
예제 #26
0
 /// <summary>
 /// Queues a new worker thread invoking the specified method.
 /// </summary>
 /// <param name="method">The method to invoke.</param>
 public void QueueWorker(ParameterDelegate method)
 {
     method.DynamicInvoke();
 }
예제 #27
0
 public void QueueWorker(ParameterDelegate method, object parameter)
 {
     ThreadPool.QueueUserWorkItem(new WaitCallback(method), parameter);
 }
예제 #28
0
 /// <summary>
 /// Starts a new thread invoking the specified method with the parameter provided.
 /// </summary>
 /// <param name="method">The method to invoke.</param>
 /// <param name="parameter">The method parameter.</param>
 public void Start(ParameterDelegate method, object parameter)
 {
     method.DynamicInvoke(parameter);
 }
예제 #29
0
 /// <summary>
 /// Queues a new worker thread invoking the specified method.
 /// </summary>
 /// <param name="method">The method to invoke.</param>
 public void QueueWorker(ParameterDelegate method)
 {
 }
예제 #30
0
 /// <summary>
 /// Queues a new worker thread invoking the specified method with the parameter provided.
 /// </summary>
 /// <param name="method">The method to invoke.</param>
 /// <param name="parameter">The method parameter.</param>
 public void QueueWorker(ParameterDelegate method, object parameter)
 {
     method.DynamicInvoke(parameter);
 }
예제 #31
0
 /// <summary>
 /// Queues a new worker thread invoking the specified method with the parameter provided.
 /// </summary>
 /// <param name="method">The method to invoke.</param>
 /// <param name="parameter">The method parameter.</param>
 public void QueueWorker(ParameterDelegate method, object parameter)
 {
 }
        protected void CreateDelegates()
        {
            // Filter for celestial bodies
            if (targetBody != null && string.IsNullOrEmpty(biome))
            {
                AddParameter(new ParameterDelegate<Vessel>("Destination: " + targetBody.theName,
                    subj => FlightGlobals.currentMainBody == targetBody, true));
            }

            // Filter for biome
            if (!string.IsNullOrEmpty(biome))
            {
                Biome b = new Biome(targetBody, biome);
                string title = b.IsKSC() ? "Location: " : "Biome: ";

                AddParameter(new ParameterDelegate<Vessel>(title + b,
                    subj => CheckBiome(FlightGlobals.ActiveVessel)));
            }

            // Filter for situation
            if (situation != null)
            {
                AddParameter(new ParameterDelegate<Vessel>("Situation: " + situation.Value.Print(),
                    subj => FlightGlobals.ActiveVessel != null && ScienceUtil.GetExperimentSituation(FlightGlobals.ActiveVessel) == situation));
            }

            // Filter for location
            if (location != null)
            {
                AddParameter(new ParameterDelegate<Vessel>("Location: " + location,
                    subj => FlightGlobals.ActiveVessel != null && ((location != BodyLocation.Surface) ^ FlightGlobals.ActiveVessel.LandedOrSplashed)));
            }

            // Add the experiments
            foreach (string exp in experiment)
            {
                string experimentStr = string.IsNullOrEmpty(exp) ? "Any" : ExperimentName(exp);
                ContractParameter experimentParam = AddParameter(new ParameterDelegate<Vessel>("Experiment: " +
                    experimentStr, subj => recoveryDone.ContainsKey(exp)));

                // Add the subject
                ContractParameter subjectParam = new ParameterDelegate<Vessel>("", subj => true);
                subjectParam.ID = exp + "Subject";
                experimentParam.AddParameter(subjectParam);

                // Filter for recovery
                if (recoveryMethod != ScienceRecoveryMethod.None)
                {
                    ContractParameter recoveryParam = experimentParam.AddParameter(new ParameterDelegate<Vessel>("Recovery: " +
                        RecoveryMethod(exp).Print(), subj => false));
                }
            }
        }
        protected void CreateDelegates()
        {
            if (ParameterCount < 1)
            {
                LoggingUtil.LogDebug(this, "Adding EVA parameter...");
                evaParam = new ParameterDelegate<MonolithParameter>("Send a Kerbal on EVA", x => CheckParameters(MonolithState.STARTED));
                AddParameter(evaParam);

                LoggingUtil.LogDebug(this, "Adding approach parameter...");
                approachParam = new ParameterDelegate<MonolithParameter>("", x => !approachParam.hidden && CheckParameters(MonolithState.EVA));
                approachParam.hidden = true;
                AddParameter(approachParam);

                LoggingUtil.LogDebug(this, "Adding 'full of stars' parameter...");
                fullofstarsParam = new ParameterDelegate<MonolithParameter>("...it's full of stars!", x => !fullofstarsParam.hidden && CheckParameters(MonolithState.FULL_OF_STARS_FINAL));
                fullofstarsParam.hidden = true;
                AddParameter(fullofstarsParam);
            }

            bool changeMade = false;
            if (currentState >= MonolithState.EVA)
            {
                if (approachParam.hidden)
                {
                    LoggingUtil.LogDebug(this, "Unhiding approach parameter...");
                    approachParam.SetTitle("Approach the monolith with " + candidateName);
                    changeMade = true;
                    approachParam.hidden = false;
                }
            }

            if (currentState >= MonolithState.FULL_OF_STARS1)
            {
                if (fullofstarsParam.hidden)
                {
                    LoggingUtil.LogDebug(this, "Unhiding 'full of stars' parameter...");
                    changeMade = true;
                    fullofstarsParam.hidden = false;
                }
            }

            if (changeMade)
            {
                ContractConfigurator.ContractConfigurator.OnParameterChange.Fire(Root, this);
            }
        }