Example #1
0
		internal HttpServer(int listenPort, RelayNode node)
		{
			_getContextCallback = GetContextCallback;
			_listenPrefix = GetListenPrefix(listenPort);
			_listener = new HttpListener();
			_listener.Prefixes.Add(_listenPrefix);
			_node = node;
		}
Example #2
0
        public void Reload(RelayNode reloadNode)
        {
            foreach (RelayNode node in all) if (node.Equals(reloadNode)) node.Reload();

            foreach (RelayNode node in comSats) if (node.Equals(reloadNode)) node.Reload();

            foreach (RelayNode node in commandStations) if (node.Equals(reloadNode)) node.Reload();
        }
Example #3
0
 public RelayPath GetCommandPath(RelayNode start)
 {
     double compare = double.MaxValue;
     RelayPath output = null;
     foreach (RelayNode node in commandStations)
     {
         if (!start.Equals(node) && node.HasCommand)
         {
             RelayPath tmp = findShortestRelayPath(start, node);
             if (tmp != null && tmp.Length < compare)
             {
                 output = tmp;
                 compare = tmp.Length;
             }
         }
     }
     return output;
 }
Example #4
0
        public RemoteCore(Vessel v, float energyDrain)
        {
            if (v == null) return;
            vessel = v;
            this.EnergyDrain = energyDrain;

            settings = new SatSettings(this);
            computer = new FlightComputer(this);
            flightComputerGUI = new FlightComputerGUI(this);

            Rnode = new RelayNode(vessel);

            try
            {
                vessel.OnFlyByWire -= new FlightInputCallback(this.drive);
            }
            catch { }
            try
            {
                vessel.OnFlyByWire += new FlightInputCallback(this.drive);
            }
            catch { }

            GetCommandPath();

            UpdateOtherModules();

            planetariumCamera = (PlanetariumCamera)GameObject.FindObjectOfType(typeof(PlanetariumCamera));

            obj = new GameObject("Line");

            line = null;

            obj.layer = 9;
            line = obj.AddComponent<LineRenderer>();
            line.useWorldSpace = true;
            line.material = new Material(Shader.Find("Particles/Additive"));
            line.SetColors(Color.blue, Color.blue);
            line.SetWidth(0, 0);

            localControl = vessel.GetCrewCount() > 0 || MechJeb;
        }
Example #5
0
 List<RelayNode> reconstructPath(Dictionary<RelayNode, RelayNode> cameFrom, RelayNode curNode)
 {
     List<RelayNode> tmp = null;
     if (cameFrom.ContainsKey(curNode))
     {
         tmp = reconstructPath(cameFrom, cameFrom[curNode]);
         tmp.Add(curNode);
     }
     else
     {
         tmp = new List<RelayNode>() { curNode };
     }
     return tmp;
 }
Example #6
0
        bool lineOfSight(RelayNode na, RelayNode nb)
        {
            if (CheatOptions.InfiniteEVAFuel)
                return true;

            Vector3d a = na.Position;
            Vector3d b = nb.Position;
            foreach (CelestialBody referenceBody in FlightGlobals.Bodies)
            {
                Vector3d bodyFromA = referenceBody.position - a;
                Vector3d bFromA = b - a;
                if (Vector3d.Dot(bodyFromA, bFromA) > 0)
                {
                    Vector3d bFromAnorm = bFromA.normalized;
                    if (Vector3d.Dot(bodyFromA, bFromAnorm) < bFromA.magnitude)
                    { // check lateral offset from line between b and a
                        Vector3d lateralOffset = bodyFromA - Vector3d.Dot(bodyFromA, bFromAnorm) * bFromAnorm;
                        if (lateralOffset.magnitude < (referenceBody.Radius - 5))
                        {
                            return false;
                        }
                    }
                }
            }
            return true;
        }
Example #7
0
        bool inRange(RelayNode na, RelayNode nb)
        {
            if (CheatOptions.InfiniteEVAFuel)
                return true;

            float distance = (float)(na.Position - nb.Position).magnitude / 1000;

            if (na.HasAntenna && nb.HasAntenna && na.AntennaRange >= distance && nb.AntennaRange >= distance) { return true; }
            if (na.HasDish && nb.HasAntenna && ((nb.AntennaRange * 2) >= distance))
            {
                foreach (DishData naData in na.DishData)
                {
                    if (((naData.pointedAt.Equals(nb.Orbits) && !na.Orbits.Equals(nb.Orbits)) || naData.pointedAt.Equals(nb.ID)) && (naData.dishRange >= distance)) { return true; }
                }
            }

            if (nb.HasDish && na.HasAntenna && ((na.AntennaRange * 2) >= distance))
            {
                foreach (DishData nbData in nb.DishData)
                {
                    if (((nbData.pointedAt.Equals(na.Orbits) && !nb.Orbits.Equals(na.Orbits)) || nbData.pointedAt.Equals(na.ID)) && (nbData.dishRange >= distance)) { return true; }
                }
            }

            if (na.HasDish && nb.HasDish)
            {

                bool aDish = false;
                bool bDish = false;
                foreach (DishData naData in na.DishData)
                {
                    if (((naData.pointedAt.Equals(nb.Orbits) && !na.Orbits.Equals(nb.Orbits)) || naData.pointedAt.Equals(nb.ID)) && (naData.dishRange >= distance)) { aDish = true; break; }
                }
                foreach (DishData nbData in nb.DishData)
                {
                    if (((nbData.pointedAt.Equals(na.Orbits) && !nb.Orbits.Equals(na.Orbits)) || nbData.pointedAt.Equals(na.ID)) && (nbData.dishRange >= distance)) { bDish = true; break; }
                }

                return aDish && bDish;
            }

            return false;
        }
Example #8
0
 bool InContactWith(RelayNode other)
 {
     return contacts.Contains(other.ID);
 }
Example #9
0
        /// <summary>
        /// Scripts that use UpdateManager and run on clients as well as on server shall be added here.
        /// </summary>
        private void RegisterScripts_ClientAndServer()
        {
            #region Attached

            RegisterForBlock(new MyObjectBuilderType[] { typeof(MyObjectBuilder_MotorStator), typeof(MyObjectBuilder_MotorAdvancedStator), typeof(MyObjectBuilder_MotorSuspension) },
                             block => RegisterForUpdates(100, (new StatorRotor.Stator(block)).Update, block));

            RegisterForBlock(typeof(MyObjectBuilder_ExtendedPistonBase), (block) => {
                Piston.PistonBase pistonBase = new Piston.PistonBase(block);
                RegisterForUpdates(100, pistonBase.Update, block);
            });

            RegisterForBlock(typeof(MyObjectBuilder_ShipConnector), (block) => {
                Connector conn = new Connector(block);
                RegisterForUpdates(10, conn.Update, block);
            });

            RegisterForBlock(typeof(MyObjectBuilder_LandingGear), (block) => {
                if (!Hacker.IsHacker(block))
                {
                    new LandingGear(block);
                }
            });

            #endregion

            #region Antenna Communication

            Action <IMyCubeBlock> nodeConstruct = block => {
                RelayNode node = new RelayNode(block);
                RegisterForUpdates(100, node.Update100, block);
            };

            RegisterForBlock(typeof(MyObjectBuilder_Beacon), nodeConstruct);
            RegisterForBlock(typeof(MyObjectBuilder_LaserAntenna), nodeConstruct);
            RegisterForBlock(typeof(MyObjectBuilder_RadioAntenna), nodeConstruct);

            RegisterForCharacter(character => {
                if (character.IsPlayer)
                {
                    RelayNode node = new RelayNode(character);
                    RegisterForUpdates(100, node.Update100, (IMyEntity)character);
                }
            });

            RegisterForBlock(typeof(MyObjectBuilder_MyProgrammableBlock), block => {
                ProgrammableBlock pb = new ProgrammableBlock(block);
                if (MyAPIGateway.Multiplayer.IsServer)
                {
                    RegisterForUpdates(100, pb.Update100, block);
                }
            });

            RegisterForBlock(typeof(MyObjectBuilder_TextPanel), block => {
                TextPanel tp = new TextPanel(block);
                if (MyAPIGateway.Multiplayer.IsServer)
                {
                    RegisterForUpdates(100, tp.Update100, block);
                }
            });

            RegisterForBlock(typeof(MyObjectBuilder_Projector), block => {
                Projector p = new Projector(block);
                if (MyAPIGateway.Session.Player != null)
                {
                    RegisterForUpdates(100, p.Update100, block);
                    RegisterForUpdates(1, p.Update1, block);
                }
            });

            if (MyAPIGateway.Session.Player != null)
            {
                new Player();
            }

            #endregion

            #region Autopilot

            if (!MyAPIGateway.Multiplayer.IsServer)
            {
                //RadarEquipment.Definition apRadar = new RadarEquipment.Definition()
                //{
                //	Radar = true,
                //	LineOfSight = false,
                //	MaxTargets_Tracking = 3,
                //	MaxPowerLevel = 1000
                //};

                Action <IMyCubeBlock> apConstruct = (block) => {
                    if (ShipAutopilot.IsAutopilotBlock(block))
                    {
                        nodeConstruct(block);
                        new AutopilotTerminal(block);
                        //RadarEquipment r = new RadarEquipment(block, apRadar, block);
                        //RegisterForUpdates(100, r.Update100, block);
                    }
                };

                if (ServerSettings.GetSetting <bool>(ServerSettings.SettingName.bUseRemoteControl))
                {
                    RegisterForBlock(typeof(MyObjectBuilder_RemoteControl), apConstruct);
                }
                RegisterForBlock(typeof(MyObjectBuilder_Cockpit), apConstruct);
            }

            if (ServerSettings.GetSetting <bool>(ServerSettings.SettingName.bAirResistanceBeta))
            {
                RegisterForGrid(grid => {
                    AeroEffects aero = new AeroEffects(grid);
                    RegisterForUpdates(1, aero.Update1, grid);
                    if (MyAPIGateway.Multiplayer.IsServer)
                    {
                        RegisterForUpdates(100, aero.Update100, grid);
                    }
                });
                RegisterForBlock(typeof(MyObjectBuilder_Cockpit), block => RegisterForUpdates(1, (new CockpitTerminal(block)).Update1, block));
            }

            #endregion

            #region Radar

            if (ServerSettings.GetSetting <bool>(ServerSettings.SettingName.bAllowRadar))
            {
                RegisterForBlock(typeof(MyObjectBuilder_Beacon), (block) => {
                    if (RadarEquipment.IsDefinedRadarEquipment(block))
                    {
                        new RadarEquipment(block);
                    }
                });
                RegisterForBlock(typeof(MyObjectBuilder_RadioAntenna), (block) => {
                    if (RadarEquipment.IsDefinedRadarEquipment(block))
                    {
                        new RadarEquipment(block);
                    }
                });
                RegisterForUpdates(100, RadarEquipment.UpdateAll);
            }

            #endregion

            #region Terminal Control

            RegisterForBlock(new MyObjectBuilderType[] { typeof(MyObjectBuilder_RadioAntenna), typeof(MyObjectBuilder_LaserAntenna) }, block => new ManualMessage(block));

            #endregion Terminal Control

            #region Weapon Control

            if (ServerSettings.GetSetting <bool>(ServerSettings.SettingName.bAllowWeaponControl))
            {
                #region Turrets

                Action <IMyCubeBlock> constructor;
                if (ServerSettings.GetSetting <bool>(ServerSettings.SettingName.bAllowGuidedMissile))
                {
                    constructor = block => {
                        if (!WeaponTargeting.ValidWeaponBlock(block))
                        {
                            return;
                        }
                        Turret t = new Turret(block);
                        RegisterForUpdates(1, t.Update_Targeting, block);
                        if (GuidedMissileLauncher.IsGuidedMissileLauncher(block))
                        {
                            GuidedMissileLauncher gml = new GuidedMissileLauncher(t);
                            RegisterForUpdates(1, gml.Update1, block);
                        }
                    }
                }
                ;
                else
                {
                    constructor = block => {
                        if (!WeaponTargeting.ValidWeaponBlock(block))
                        {
                            return;
                        }
                        Turret t = new Turret(block);
                        RegisterForUpdates(1, t.Update_Targeting, block);
                    }
                };

                RegisterForBlock(typeof(MyObjectBuilder_LargeGatlingTurret), constructor);
                RegisterForBlock(typeof(MyObjectBuilder_LargeMissileTurret), constructor);
                RegisterForBlock(typeof(MyObjectBuilder_InteriorTurret), constructor);

                #endregion

                #region Fixed

                if (ServerSettings.GetSetting <bool>(ServerSettings.SettingName.bAllowGuidedMissile))
                {
                    constructor = block => {
                        if (!WeaponTargeting.ValidWeaponBlock(block))
                        {
                            return;
                        }
                        FixedWeapon w = new FixedWeapon(block);
                        RegisterForUpdates(1, w.Update_Targeting, block);
                        if (GuidedMissileLauncher.IsGuidedMissileLauncher(block))
                        {
                            GuidedMissileLauncher gml = new GuidedMissileLauncher(w);
                            RegisterForUpdates(1, gml.Update1, block);
                        }
                    };
                }
                else
                {
                    constructor = block => {
                        if (!WeaponTargeting.ValidWeaponBlock(block))
                        {
                            return;
                        }
                        FixedWeapon w = new FixedWeapon(block);
                        RegisterForUpdates(1, w.Update_Targeting, block);
                    }
                };

                RegisterForBlock(typeof(MyObjectBuilder_SmallGatlingGun), constructor);
                RegisterForBlock(typeof(MyObjectBuilder_SmallMissileLauncher), constructor);
                RegisterForBlock(typeof(MyObjectBuilder_SmallMissileLauncherReload), constructor);

                #endregion

                // apparently missiles do not have their positions synced
                RegisterForUpdates(1, GuidedMissile.Update1);
                RegisterForUpdates(10, GuidedMissile.Update10);
                RegisterForUpdates(100, GuidedMissile.Update100);
            }
            else
            {
                Log.DebugLog("Weapon Control is disabled", Logger.severity.INFO);
            }

            #endregion

            #region Solar

            if (!MyAPIGateway.Multiplayer.IsServer)
            {
                RegisterForBlock(typeof(MyObjectBuilder_OxygenFarm), (block) => new Solar(block));
                RegisterForBlock(typeof(MyObjectBuilder_SolarPanel), (block) => new Solar(block));
            }

            #endregion

            new ChatHandler();
            Globals.Update100();
            RegisterForUpdates(100, Globals.Update100);

            Action <IMyCubeBlock> act = (block) => MainCockpitFix.AddController((IMyShipController)block);
            RegisterForBlock(typeof(MyObjectBuilder_Cockpit), act);
            RegisterForBlock(typeof(MyObjectBuilder_RemoteControl), act);
        }
Example #10
0
 public static float nodeDistance(RelayNode na, RelayNode nb)
 {
     return (float)(na.Position - nb.Position).magnitude;
 }
Example #11
0
 public CBOrV(RelayNode inNode, string inPrefix)
 {
     this.RefNode = inNode;
     this.RefBody = null;
     this.Prefix = inPrefix;
     Children = new List<CBOrV>();
 }
Example #12
0
        public CBOrV(CelestialBody inBody, RelayNode inExclNode, string inPrefix)
        {
            this.RefBody = inBody;
            this.RefNode = null;
            this.Prefix = inPrefix;
            this.ExclNode = inExclNode;

            Children = new List<CBOrV>();

            if (RefBody.name.Equals("Kerbin"))
                Children.Add(new CBOrV(new RelayNode(), Prefix + "	"));

            if (RefBody.orbitingBodies.Count > 0)
                foreach (CelestialBody b in RefBody.orbitingBodies)
                {
                    Children.Add(new CBOrV(b, ExclNode, Prefix + "	"));
                }
            foreach (RelayNode n in RTGlobals.network.all)
                if (n.MainBodyIs(RefBody) && !ExclNode.Equals(n) && (n.HasDish || n.HasAntenna))
                    Children.Add(new CBOrV(n, Prefix + "	"));
            if (Children.Count > 1)
                Children.Sort(delegate(CBOrV n1, CBOrV n2) { return n1.semiMajorAxis.CompareTo(n2.semiMajorAxis); });
        }
Example #13
0
 public Target(string bodyOrNode)
 {
     foreach (CelestialBody bodies in FlightGlobals.Bodies)
     {
         if (bodies.name.ToLower().Equals(bodyOrNode.ToLower()))
         {
             this.referenceBody = bodies;
             this.isPlanet = true;
             return;
         }
     }
     foreach (RelayNode nodes in RTGlobals.network.all)
     {
         if (nodes.ID.Equals(bodyOrNode))
         {
             this.node = nodes;
         }
     }
     if (this.referenceBody == null && this.node == null)
     {
         emptytarget = true;
     }
 }
Example #14
0
 public Target(RelayNode nodeIn)
 {
     this.node = nodeIn;
 }
Example #15
0
        public void Open(RelayNode nodeIn)
        {
            if (show && nodeIn.Equals(this.node))
            {
                Close();
                return;
            }
            this.node = nodeIn;

            RTGlobals.targets = new List<Target>();

            CBOrV SortNetwork = new CBOrV(Planetarium.fetch.Sun, this.node);
            SortNetwork.createTargets(ref RTGlobals.targets);

            RTGlobals.targets.Add(new Target());
            RTGlobals.targets[RTGlobals.targets.Count - 1].GUIListname = RTGlobals.targets[RTGlobals.targets.Count - 1].Name;
            RTGlobals.targets[RTGlobals.targets.Count - 1].color = Color.red;

            settingNodes = new List<SatSettingNode>();

            if (node.IsLoaded)
                LoadFromLoaded();
            else
                LoadFromUnLoaded();
            this.show = true;
        }
Example #16
0
 public bool inContactWith(RelayNode node, RelayNode other)
 {
     return (findShortestRelayPath(node, other) != null);
 }
Example #17
0
        bool inRange(RelayNode na, RelayNode nb)
        {
            if (CheatOptions.InfiniteEVAFuel)
                return true;

            // NK refactor distance functions
            float distance = nodeDistance(na, nb) * 0.001f; // convert to km
            return maxDistance(na, nb) >= distance;
        }
Example #18
0
        RelayPath findShortestRelayPath(RelayNode start, RelayNode goal)
        {
            HashSet<RelayNode> closedSet = new HashSet<RelayNode>();
            HashSet<RelayNode> openSet = new HashSet<RelayNode>();

            Dictionary<RelayNode, RelayNode> cameFrom = new Dictionary<RelayNode, RelayNode>();
            Dictionary<RelayNode, double> gScore = new Dictionary<RelayNode, double>();
            Dictionary<RelayNode, double> hScore = new Dictionary<RelayNode, double>();
            Dictionary<RelayNode, double> fScore = new Dictionary<RelayNode, double>();

            openSet.Add(start);

            double startBaseHeuristic = (start.Position - goal.Position).magnitude;
            gScore[start] = 0.0;
            hScore[start] = startBaseHeuristic;
            fScore[start] = startBaseHeuristic;

            HashSet<RelayNode> neighbors = new HashSet<RelayNode>(all);
            neighbors.Add(start);
            neighbors.Add(goal);

            RelayPath path = null;
            while (openSet.Count > 0)
            {
                RelayNode current = null;
                double currentBestScore = double.MaxValue;
                foreach (KeyValuePair<RelayNode, double> pair in fScore)
                {
                    if (openSet.Contains(pair.Key) && pair.Value < currentBestScore)
                    {
                        current = pair.Key;
                        currentBestScore = pair.Value;
                    }
                }
                if (current == goal)
                {
                    path = new RelayPath(reconstructPath(cameFrom, goal));
                    break;
                }
                openSet.Remove(current);
                closedSet.Add(current);
                foreach (RelayNode neighbor in neighbors)
                {
                    if (!closedSet.Contains(neighbor) && inRange(neighbor, current) && lineOfSight(neighbor, current))
                    {
                        //double tentGScore = gScore[current] - (neighbor.Position - current.Position).magnitude;
                        double tentGScore = gScore[current] + (neighbor.Position - current.Position).magnitude;

                        bool tentIsBetter = false;
                        if (!openSet.Contains(neighbor))
                        {
                            openSet.Add(neighbor);
                            hScore[neighbor] = (neighbor.Position - goal.Position).magnitude;
                            tentIsBetter = true;
                        }
                        else if (tentGScore < gScore[neighbor])
                        {
                            tentIsBetter = true;
                        }

                        if (tentIsBetter)
                        {
                            cameFrom[neighbor] = current;
                            gScore[neighbor] = tentGScore;
                            fScore[neighbor] = tentGScore + hScore[neighbor];
                        }
                    }
                }

            }

            return path;
        }
Example #19
0
        public static float maxDistance(RelayNode na, RelayNode nb)
        {
            float aRange = 0, bRange = 0, aSumRange = 0, bSumRange = 0;
            float clamp = 1000f;
            bool aDish = false, bDish = false;

            // get max-range dish pointed at other node
            if (na.HasDish)
            {
                foreach (DishData naData in na.DishData)
                {
                    if (((naData.pointedAt.Equals(nb.Orbits) && !na.Orbits.Equals(nb.Orbits)) || naData.pointedAt.Equals(nb.ID)))
                    {
                        aDish = true;
                        if (naData.dishRange >= aRange)
                            aRange = naData.dishRange;
                        aSumRange += naData.dishRange;
                    }

                }
            }
            if(RTGlobals.useMultiple)
                aRange = (float)Math.Round(aRange + (aSumRange - aRange) * 0.25f);

            if(nb.HasDish)
            {
                foreach (DishData nbData in nb.DishData)
                {
                    if (((nbData.pointedAt.Equals(na.Orbits) && !nb.Orbits.Equals(na.Orbits)) || nbData.pointedAt.Equals(na.ID)))
                    {
                        bDish = true;
                        if (nbData.dishRange >= bRange)
                            aRange = nbData.dishRange;
                        bSumRange += nbData.dishRange;
                    }
                }
            }
            if (RTGlobals.useMultiple)
                bRange = (float)Math.Round(bRange + (bSumRange - bRange) * 0.25f);

            // if no dish, get antenna. If neither, fail.
            if (!aDish)
            {
                clamp = 100f;
                if (na.HasAntenna)
                    aRange = na.AntennaRange;
                else
                    return 0f;
            }
            if (!bDish)
            {
                clamp = 100f;
                if (nb.HasAntenna)
                    bRange = nb.AntennaRange;
                else
                    return 0f;
            }

            // return distance using distance function; clamp to 1000x min range if both dishes or 100x if one or both isn't
            if (aRange < bRange)
            {
                return distFunc(aRange, bRange, clamp * aRange);
            }
            else
            {
                return distFunc(bRange, aRange, clamp * bRange);
            }
        }