Exemplo n.º 1
0
 ///<summary>
 /// Returns the name of the biome for a goepostion. Used in the calling suffix.
 /// takes parameter <CelestialBody>, <GeoCoordinates>
 ///</summary>
 public StringValue GetBiomeAt(BodyTarget body, GeoCoordinates coordinate)
 {
     return(GetScannedBiomeName(body.Body, coordinate.Longitude, coordinate.Latitude));
 }
Exemplo n.º 2
0
        public override void Execute(SharedObjects shared)
        {
            string listType = PopValueAssert(shared).ToString();
            var    list     = new ListValue();

            switch (listType)
            {
            case "bodies":
                foreach (CelestialBody cBody in FlightGlobals.fetch.bodies)
                {
                    list.Add(BodyTarget.CreateOrGetExisting(cBody, shared));
                }
                break;

            case "targets":
                foreach (var vessel in FlightGlobals.Vessels)
                {
                    if (vessel == shared.Vessel)
                    {
                        continue;
                    }
                    list.Add(VesselTarget.CreateOrGetExisting(vessel, shared));
                }
                break;

            case "resources":
            case "parts":
            case "engines":
            case "rcs":
            case "sensors":
            case "elements":
            case "dockingports":
                list = shared.Vessel.PartList(listType, shared);
                break;

            case "files":
                list = ListValue.CreateList(shared.VolumeMgr.CurrentDirectory.ListAsLexicon().Values.ToList());
                break;

            case "volumes":
                list = ListValue.CreateList(shared.VolumeMgr.Volumes.Values.ToList());
                break;

            case "processors":
                list = ListValue.CreateList(shared.ProcessorMgr.processors.Values.ToList().Select(processor => PartModuleFieldsFactory.Construct(processor, shared)));
                break;

            case "fonts":
                foreach (Font f in Resources.FindObjectsOfTypeAll <Font>())
                {
                    list.Add(new StringValue(f.name));
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            AssertArgBottomAndConsume(shared);

            ReturnValue = list;
        }
Exemplo n.º 3
0
        private Guid GetTargetGuid(Structure target)
        {
            var api = RemoteTechHook.Instance;

            if (target is StringValue)
            {
                string targetString = target.ToString();
                if (targetString.Equals(NoTargetString, StringComparison.InvariantCultureIgnoreCase))
                {
                    return(api.GetNoTargetGuid());
                }
                else if (targetString.Equals(ActiveVesselString, StringComparison.InvariantCultureIgnoreCase))
                {
                    return(api.GetActiveVesselGuid());
                }
                else
                {
                    IEnumerable <string> groundStations = api.GetGroundStations();
                    foreach (var groundStation in groundStations)
                    {
                        if (targetString.Equals(groundStation))
                        {
                            return(api.GetGroundStationGuid(groundStation));
                        }
                    }

                    var body = FlightGlobals.Bodies.Where(b => b.bodyName.Equals(targetString, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();
                    if (body != null)
                    {
                        return(api.GetCelestialBodyGuid(body));
                    }
                    else
                    {
                        var vessel = FlightGlobals.Vessels.FirstOrDefault(v => v.vesselName.Equals(targetString, StringComparison.InvariantCultureIgnoreCase));
                        if (vessel != null)
                        {
                            if (partModule.vessel.id.Equals(vessel.id))
                            {
                                throw new KOSInvalidFieldValueException("Current vessel can't be the target");
                            }

                            return(vessel.id);
                        }
                    }
                }
            }
            else if (target is BodyTarget)
            {
                BodyTarget targetBody = (BodyTarget)target;
                return(api.GetCelestialBodyGuid(targetBody.Body));
            }
            else if (target is VesselTarget)
            {
                VesselTarget targetVessel = (VesselTarget)target;

                if (partModule.vessel.id.Equals(targetVessel.Vessel.id))
                {
                    throw new KOSInvalidFieldValueException("Current vessel can't be the target");
                }

                return(targetVessel.Vessel.id);
            }

            throw new KOSInvalidFieldValueException("Acceptable values are: \"" + NoTargetString + "\", \"" + ActiveVesselString +
                                                    "\", name of a ground station, name of a body, name of a vessel, Body, Vessel");
        }
Exemplo n.º 4
0
        public void SendToSOIChangeNotifyees(GameEvents.HostedFromToAction <Vessel, CelestialBody> evt)
        {
            UniqueSetValue <UserDelegate> notifyees = GetSOIChangeNotifyees(evt.host);

            foreach (UserDelegate del in notifyees)
            {
                if (UserDelgateIsAcceptable(del))
                {
                    Shared.Cpu.AddTrigger(del, InterruptPriority.CallbackOnce, Shared.Cpu.NextTriggerInstanceId, false, BodyTarget.CreateOrGetExisting(evt.@from, Shared), BodyTarget.CreateOrGetExisting(evt.to, Shared));
                }
            }
        }
Exemplo n.º 5
0
 public void Awake()
 {
     VesselTarget.ClearInstanceCache();
     BodyTarget.ClearInstanceCache();
     Destroy(this);
 }
Exemplo n.º 6
0
 ///<summary>
 /// Suffix funtion for returing completed percentage of a scantype for a body
 /// takes the kos parameters <BodyTarget>, <StrinValue> scantype
 ///</summary>
 public ScalarDoubleValue GetCoverage(BodyTarget body, StringValue scantype)
 {
     return(SCANWrapper.GetCoverage(scantype, body.Body));
 }
Exemplo n.º 7
0
 ///<summary>
 /// Suffix function for returing the altitude for a spot
 /// takes the kos parameters <BodyTarget>, <GeoCoordinates>
 ///</summary>
 public ScalarDoubleValue GetAltAtSuffix(BodyTarget body, GeoCoordinates coordinate)
 {
     return(GetAltAt(body.Body, coordinate.Longitude, coordinate.Latitude));
 }
Exemplo n.º 8
0
        public override void AddTo(SharedObjects shared)
        {
            sharedObj = shared;

            shared.BindingMgr.AddGetter("CORE", () => new Core((kOSProcessor)shared.Processor, shared));
            shared.BindingMgr.AddGetter("SHIP", () => ship);
            // These are now considered shortcuts to SHIP:suffix
            foreach (var scName in VesselTarget.ShortCuttableShipSuffixes)
            {
                shared.BindingMgr.AddGetter(scName, () => VesselShortcutGetter(scName));
            }

            shared.BindingMgr.AddSetter("TARGET", val =>
            {
                if (shared.Vessel != FlightGlobals.ActiveVessel)
                {
                    throw new kOS.Safe.Exceptions.KOSSituationallyInvalidException("TARGET can only be set for the Active Vessel");
                }
                var targetable = val as IKOSTargetable;
                if (targetable != null)
                {
                    VesselUtils.SetTarget(targetable, shared.Vessel);
                    return;
                }

                if (!string.IsNullOrEmpty(val.ToString().Trim()))
                {
                    var body = VesselUtils.GetBodyByName(val.ToString());
                    if (body != null)
                    {
                        VesselUtils.SetTarget(body, shared.Vessel);
                        return;
                    }

                    var vessel = VesselUtils.GetVesselByName(val.ToString(), shared.Vessel);
                    if (vessel != null)
                    {
                        VesselUtils.SetTarget(vessel, shared.Vessel);
                        return;
                    }
                }
                //Target not found, if we have a target we clear it
                VesselUtils.UnsetTarget();
            });

            shared.BindingMgr.AddGetter("TARGET", () =>
            {
                var target = (shared.Vessel == FlightGlobals.ActiveVessel) ? FlightGlobals.fetch.VesselTarget : shared.Vessel.targetObject;

                var vessel = target as Vessel;
                if (vessel != null)
                {
                    return(VesselTarget.CreateOrGetExisting(vessel, shared));
                }
                var body = target as CelestialBody;
                if (body != null)
                {
                    return(BodyTarget.CreateOrGetExisting(body, shared));
                }
                var dockingNode = target as ModuleDockingNode;
                if (dockingNode != null)
                {
                    return(VesselTarget.CreateOrGetExisting(dockingNode.vessel, shared)[dockingNode.part]);
                }

                throw new kOS.Safe.Exceptions.KOSSituationallyInvalidException("No TARGET is selected");
            });

            shared.BindingMgr.AddGetter("HASTARGET", () =>
            {
                // the ship has a target if the object does not equal null.
                return((shared.Vessel == FlightGlobals.ActiveVessel ?
                        FlightGlobals.fetch.VesselTarget : shared.Vessel.targetObject) != null);
            });
        }