Пример #1
0
    public void CreateAnchorSave(StationBase station, StationType type)
    {
        CurrentSave = new SaveGame();

        //create a regular save and then fill anchor with data

        if (type == StationType.JumpGate)
        {
            JumpGate gate = (JumpGate)station;
            CurrentSave.SpawnSystem      = gate.TargetSystem;
            CurrentSave.SpawnStationID   = gate.ExitGateID;
            CurrentSave.SpawnStationType = StationType.JumpGate;
        }
        else if (type == StationType.JumpHole)
        {
        }
        else if (type == StationType.Station)
        {
            CurrentSave.SpawnSystem      = GameManager.Inst.WorldManager.CurrentSystem.ID;
            CurrentSave.SpawnStationID   = station.ID;
            CurrentSave.SpawnStationType = type;
        }

        SaveWorldData();
        SavePlayerData(false);

        SerializeSave();

        LevelAnchor anchor = GameObject.FindObjectOfType <LevelAnchor>();

        anchor.SpawnSystem = CurrentSave.SpawnSystem;
        anchor.ProfileName = GameManager.Inst.PlayerProgress.ProfileName;
    }
        private void Save(StationBase station)
        {
            _lastSaved = DateTime.Now;

            if (station == null)
            {
                return;
            }
            if (LcdPanel == null)
            {
                return;
            }

            try
            {
                StationBase oldStationData = Load();
                Station.TakeSettingData(oldStationData);

                LcdPanel.CustomData = MyAPIGateway.Utilities.SerializeToXML(Station);
                Log("Station saved.");
            }
            catch (Exception exception)
            {
                MyAPIGateway.Utilities.ShowNotification("Error: Saving data: " + exception.Message, 10000, "Red");
            }
        }
Пример #3
0
    public void SpawnPlayer()
    {
        Debug.Log("Spawning in station " + GameManager.Inst.PlayerProgress.SpawnStationID);
        StationBase     station = GameObject.Find(GameManager.Inst.PlayerProgress.SpawnStationID).GetComponent <StationBase>();
        DockSessionBase session = null;

        station.Undock(PlayerShip, out session);
    }
Пример #4
0
        /// <summary>
        /// Create a new StationEditor instance
        /// </summary>
        /// <param name="station">The associated station</param>
        /// <param name="trn">From this TreeNode</param>
        public StationEditor(StationBase station, TreeNode trn)
        {
            InitializeComponent();

            this.station = station;
            this.trn     = trn;

            edtStationName.Text = station.Title;
        }
Пример #5
0
 private void Dock()
 {
     if (SelectedObject != null && SelectedObjectType == SelectedObjectType.Station)
     {
         StationBase station = (StationBase)SelectedObject;
         if (station != null)
         {
             DockSessionBase session;
             station.Dock(PlayerShip, out session);
         }
     }
 }
Пример #6
0
 public void DockComplete(StationBase dockedStation, StationType type)
 {
     GameManager.Inst.SaveGameManager.CreateAnchorSave(dockedStation, type);
     if (type == StationType.Station)
     {
         GameManager.Inst.UIManager.FadePanel.FadeOut(0.4f);
     }
     else if (type == StationType.JumpGate)
     {
         GameManager.Inst.UIManager.FadePanel.WhiteFadeOut(0.75f);
     }
 }
Пример #7
0
        public void ShowInfo(string msg, StationBase station, int maxCount = 5)
        {
            var modellist = InfoList.Where(m => m.StationName.Equals(station.StationName)).First();

            if (modellist != null)
            {
                modellist.InfoCollect.Add(msg);
                while (modellist.InfoCollect.Count > maxCount)
                {
                    modellist.InfoCollect.RemoveAt(0);
                }
            }
        }
Пример #8
0
    public DockingSession(DockGate gate, ShipBase requester, StationBase parent, bool isUndocking)
    {
        Gate          = gate;
        Requester     = requester;
        ParentStation = parent;


        if (!isUndocking)
        {
            Stage = DockingSessionStage.Granted;

            //if requester is player, turn light green
            if (requester == GameManager.Inst.PlayerControl.PlayerShip)
            {
                gate.SetGreenLight();
                _dockEnterTarget = Gate.DockingTrigger.transform.position + Gate.DockingTrigger.transform.forward * 2;
            }
            else
            {
                gate.SetRedLight();
                _dockEnterTarget = Gate.DockingTrigger.transform.position + Gate.DockingTrigger.transform.forward * 20;
            }

            gate.Open();
            gate.DockingTrigger.isTrigger = false;
        }
        else
        {
            Stage = DockingSessionStage.UndockWaiting;
            //place requester in the gate
            Vector3 enterTarget = gate.DockingTrigger.transform.position - gate.DockingTrigger.transform.forward * 4f;
            requester.transform.position = enterTarget;
            requester.transform.LookAt(gate.DockingTrigger.transform, gate.DockingTrigger.transform.up);
            gate.Open();
            gate.DockingTrigger.isTrigger = false;
            if (Requester == GameManager.Inst.PlayerControl.PlayerShip)
            {
                gate.DockingTrigger.isTrigger = true;
                GameManager.Inst.PlayerControl.PlayerShip.IsInPortal = true;
            }
            else
            {
                requester.Show();
            }

            _waitTimer = 0;
        }
    }
Пример #9
0
        public static IOutputRepresentor CreateRepresentor(StationBase station)
        {
            IOutputRepresentor outputRepresentor;

            if (station is TradeStation)
            {
                outputRepresentor = new TradeStationOutput(station);
            }
            else if (station is FactoryStation)
            {
                outputRepresentor = new FactoryStationOutput(station);
            }
            else
            {
                outputRepresentor = new DefaultOutput(station);
            }

            return(outputRepresentor);
        }
Пример #10
0
    private void AutopilotGoTo()
    {
        if (SelectedObject != null)
        {
            Vector3 gotoDest = Vector3.zero;
            if (SelectedObjectType == SelectedObjectType.Planet)
            {
                Planet  planet   = (Planet)SelectedObject;
                Vector3 distance = planet.transform.position - PlayerShip.transform.position;
                gotoDest = planet.transform.position - distance.normalized * (40f + planet.OriginalScale.x / 2f);
            }
            else if (SelectedObjectType == SelectedObjectType.Station)
            {
                StationBase station  = (StationBase)SelectedObject;
                Vector3     distance = station.transform.position - PlayerShip.transform.position;
                gotoDest = PlayerShip.transform.position + distance.normalized * (distance.magnitude - 20f);
            }

            if (gotoDest != Vector3.zero)
            {
                MacroAITask task = new MacroAITask();
                task.TaskType           = MacroAITaskType.Travel;
                task.TravelDestSystemID = GameManager.Inst.WorldManager.CurrentSystem.ID;
                task.TravelDestNodeID   = "";
                task.IsDestAStation     = false;
                Transform origin = GameObject.Find("Origin").transform;
                task.TravelDestCoord = new RelLoc(origin.position, gotoDest, origin);

                IsAutopilot             = true;
                PlayerParty.WaitTimer   = 0;
                PlayerParty.CurrentTask = task;

                PlayerParty.HasReachedDestNode = false;
                PlayerParty.DestNode           = GameManager.Inst.NPCManager.MacroAI.GetClosestNodeToLocation(task.TravelDestCoord.RealPos, GameManager.Inst.WorldManager.AllSystems[task.TravelDestSystemID]);
                Debug.Log("Autopilot dest node " + PlayerParty.DestNode.ID);
                PlayerAutopilot.Activate();
                _isMouseFlight = false;

                InputEventHandler.Instance.InputState = InputState.Autopilot;
            }
        }
    }
Пример #11
0
        void BtnLoadStationsRTClick(object sender, EventArgs e)
        {
            trvStations.Nodes.Clear();

            for (int i = 0; i < GameEngine.Instance.StationList.Count; i++)
            {
                StationBase stat = GameEngine.Instance.StationList[i];
                if (stat != null)
                {
                    TreeNode trn = trvStations.Nodes.Add(stat.Title);
                    trn.Tag = stat;

                    for (int j = 0; j < stat.Modules.Count; j++)
                    {
                        if (stat.Modules[j] != null)
                        {
                            TreeNode trnMod = trn.Nodes.Add(stat.Modules[j].GetType().ToString());
                            trnMod.Tag = stat.Modules[j];
                        }
                    }
                }
            }
        }
Пример #12
0
        public static void UpdateLcdOutput(IMyEntity entity, StationBase station, bool searchOnConnectedGrids = false)
        {
            IMyCubeGrid cubeGrid = entity.GetTopMostParent() as IMyCubeGrid;

            List <IMySlimBlock> textPanels = new List <IMySlimBlock>();

            if (cubeGrid == null)
            {
                return;
            }
            cubeGrid.GetBlocks(
                textPanels,
                e => e?.FatBlock != null && e.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_TextPanel)
                );

            if (searchOnConnectedGrids)
            {
                var connectedShips = GridApi.GetConnectedShips(entity);

                foreach (var connector in connectedShips.Keys)
                {
                    var grid = connectedShips[connector];
                    if (grid == null)
                    {
                        continue;
                    }
                    List <IMySlimBlock> panels = new List <IMySlimBlock>();
                    grid.GetBlocks(
                        panels,
                        e => e?.FatBlock != null &&
                        e.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_TextPanel)
                        );
                    textPanels.AddRange(panels);
                }
            }
            if (textPanels.Count <= 0)
            {
                return;
            }

            Dictionary <string, StringBuilder> output = new Dictionary <string, StringBuilder>();
            IOutputRepresentor outputRepresentor      = StationOutputFactory.CreateRepresentor(station);

            outputRepresentor.CreateOutput(output, cubeGrid);

            foreach (var lcd in textPanels)
            {
                var myLcd = lcd.FatBlock as IMyTextPanel;

                if (myLcd == null)
                {
                    continue;
                }
                var title = myLcd.GetPublicTitle().ToLower();

                if (title.IndexOf("info", StringComparison.Ordinal) != 0)
                {
                    continue;
                }

                foreach (KeyValuePair <string, StringBuilder> pair in output)
                {
                    string lcdTextInfo = "";

                    if (!title.Contains(pair.Key.ToLower()))
                    {
                        continue;
                    }

                    lcdTextInfo = pair.Value.ToString();

                    if (lcdTextInfo == myLcd.GetPublicText())
                    {
                        continue;
                    }

                    myLcd.WritePublicText(lcdTextInfo);
                    myLcd.ShowPublicTextOnScreen();
                }
            }
        }
Пример #13
0
 public TradeStationOutput(StationBase station) : base(station)
 {
 }
Пример #14
0
    public void GenerateSystemXML()
    {
        string id   = GameManager.Inst.SystemID;
        string path = Application.dataPath + "/GameData/StarSystem/" + id + ".xml";

        XmlWriterSettings settings = new XmlWriterSettings();

        settings.Indent              = true;
        settings.IndentChars         = "    "; // note: default is two spaces
        settings.NewLineOnAttributes = false;

        _xmlWriter = XmlWriter.Create(path, settings);

        _xmlWriter.WriteStartDocument();

        _xmlWriter.WriteDocType("system", null, null, "<!ATTLIST node id ID #IMPLIED>");

        _xmlWriter.WriteStartElement("system");
        _xmlWriter.WriteAttributeString("id", id);
        _xmlWriter.WriteAttributeString("displayname", GameManager.Inst.SystemName);

        //system location in system map
        _xmlWriter.WriteStartElement("systemlocation");
        _xmlWriter.WriteStartElement("vector3");
        _xmlWriter.WriteAttributeString("x", "0");
        _xmlWriter.WriteAttributeString("y", "0");
        _xmlWriter.WriteAttributeString("z", "0");
        _xmlWriter.WriteEndElement();
        _xmlWriter.WriteFullEndElement();

        //ambience
        _xmlWriter.WriteStartElement("ambience");

        _xmlWriter.WriteStartElement("skybox");
        _xmlWriter.WriteString(RenderSettings.skybox.name);
        _xmlWriter.WriteFullEndElement();

        _xmlWriter.WriteStartElement("ambientcolor");

        _xmlWriter.WriteStartElement("color");
        _xmlWriter.WriteAttributeString("r", RenderSettings.ambientLight.r.ToString());
        _xmlWriter.WriteAttributeString("g", RenderSettings.ambientLight.g.ToString());
        _xmlWriter.WriteAttributeString("b", RenderSettings.ambientLight.b.ToString());
        _xmlWriter.WriteEndElement();

        _xmlWriter.WriteFullEndElement();

        _xmlWriter.WriteStartElement("music");
        _xmlWriter.WriteFullEndElement();

        _xmlWriter.WriteFullEndElement();

        //origin
        GameObject origin = GameObject.Find("Origin");

        _xmlWriter.WriteStartElement("origin");
        _xmlWriter.WriteStartElement("vector3");
        _xmlWriter.WriteAttributeString("x", origin.transform.position.x.ToString());
        _xmlWriter.WriteAttributeString("y", origin.transform.position.y.ToString());
        _xmlWriter.WriteAttributeString("z", origin.transform.position.z.ToString());
        _xmlWriter.WriteEndElement();
        _xmlWriter.WriteFullEndElement();

        //suns
        Sun [] suns = GameObject.FindObjectsOfType <Sun>();
        foreach (Sun sun in suns)
        {
            _xmlWriter.WriteStartElement("sun");

            _xmlWriter.WriteStartElement("id");
            _xmlWriter.WriteString(sun.ID);
            _xmlWriter.WriteFullEndElement();

            _xmlWriter.WriteStartElement("displayname");
            _xmlWriter.WriteString(sun.DisplayName);
            _xmlWriter.WriteFullEndElement();

            _xmlWriter.WriteStartElement("location");
            _xmlWriter.WriteStartElement("vector3");
            Vector3 disposition = sun.transform.position - origin.transform.position;
            _xmlWriter.WriteAttributeString("x", disposition.x.ToString());
            _xmlWriter.WriteAttributeString("y", disposition.y.ToString());
            _xmlWriter.WriteAttributeString("z", disposition.z.ToString());
            _xmlWriter.WriteEndElement();
            _xmlWriter.WriteFullEndElement();

            _xmlWriter.WriteStartElement("scale");
            _xmlWriter.WriteStartElement("vector3");
            _xmlWriter.WriteAttributeString("x", sun.transform.localScale.x.ToString());
            _xmlWriter.WriteAttributeString("y", sun.transform.localScale.y.ToString());
            _xmlWriter.WriteAttributeString("z", sun.transform.localScale.z.ToString());
            _xmlWriter.WriteEndElement();
            _xmlWriter.WriteFullEndElement();

            _xmlWriter.WriteStartElement("sunlight");
            _xmlWriter.WriteAttributeString("intensity", sun.Sunlight.intensity.ToString());
            _xmlWriter.WriteStartElement("color");
            _xmlWriter.WriteAttributeString("r", sun.Sunlight.color.r.ToString());
            _xmlWriter.WriteAttributeString("g", sun.Sunlight.color.g.ToString());
            _xmlWriter.WriteAttributeString("b", sun.Sunlight.color.b.ToString());
            _xmlWriter.WriteEndElement();
            _xmlWriter.WriteFullEndElement();

            _xmlWriter.WriteFullEndElement();
        }

        //planets
        Planet [] planets = GameObject.FindObjectsOfType <Planet>();
        foreach (Planet planet in planets)
        {
            _xmlWriter.WriteStartElement("planet");

            _xmlWriter.WriteStartElement("id");
            _xmlWriter.WriteString(planet.ID);
            _xmlWriter.WriteFullEndElement();

            _xmlWriter.WriteStartElement("displayname");
            _xmlWriter.WriteString(planet.DisplayName);
            _xmlWriter.WriteFullEndElement();

            _xmlWriter.WriteStartElement("location");
            _xmlWriter.WriteStartElement("vector3");
            Vector3 disposition = planet.transform.position - origin.transform.position;
            _xmlWriter.WriteAttributeString("x", disposition.x.ToString());
            _xmlWriter.WriteAttributeString("y", disposition.y.ToString());
            _xmlWriter.WriteAttributeString("z", disposition.z.ToString());
            _xmlWriter.WriteEndElement();
            _xmlWriter.WriteFullEndElement();

            _xmlWriter.WriteStartElement("scale");
            _xmlWriter.WriteStartElement("vector3");
            _xmlWriter.WriteAttributeString("x", planet.OriginalScale.x.ToString());
            _xmlWriter.WriteAttributeString("y", planet.OriginalScale.y.ToString());
            _xmlWriter.WriteAttributeString("z", planet.OriginalScale.z.ToString());
            _xmlWriter.WriteEndElement();
            _xmlWriter.WriteFullEndElement();


            _xmlWriter.WriteFullEndElement();
        }

        //stations
        GameObject [] stations = GameObject.FindGameObjectsWithTag("Station");
        foreach (GameObject o in stations)
        {
            StationBase station = o.GetComponent <StationBase>();
            _xmlWriter.WriteStartElement("station");

            _xmlWriter.WriteStartElement("id");
            _xmlWriter.WriteString(station.ID);
            _xmlWriter.WriteFullEndElement();

            _xmlWriter.WriteStartElement("displayname");
            _xmlWriter.WriteString(station.DisplayName);
            _xmlWriter.WriteFullEndElement();

            _xmlWriter.WriteStartElement("stationtype");
            _xmlWriter.WriteString(station.StationType.ToString());
            _xmlWriter.WriteFullEndElement();


            _xmlWriter.WriteStartElement("location");
            _xmlWriter.WriteStartElement("vector3");
            Vector3 disposition = station.transform.position - origin.transform.position;
            _xmlWriter.WriteAttributeString("x", disposition.x.ToString());
            _xmlWriter.WriteAttributeString("y", disposition.y.ToString());
            _xmlWriter.WriteAttributeString("z", disposition.z.ToString());
            _xmlWriter.WriteEndElement();
            _xmlWriter.WriteFullEndElement();

            _xmlWriter.WriteStartElement("eulerangles");
            _xmlWriter.WriteStartElement("vector3");
            _xmlWriter.WriteAttributeString("x", station.transform.eulerAngles.x.ToString());
            _xmlWriter.WriteAttributeString("y", station.transform.eulerAngles.y.ToString());
            _xmlWriter.WriteAttributeString("z", station.transform.eulerAngles.z.ToString());
            _xmlWriter.WriteEndElement();
            _xmlWriter.WriteFullEndElement();

            foreach (StationBase neighbor in station.NeighborStations)
            {
                _xmlWriter.WriteStartElement("navneighbor");
                _xmlWriter.WriteString(neighbor.ID);
                _xmlWriter.WriteFullEndElement();
            }

            if (station.StationType == StationType.JumpGate)
            {
                JumpGate gate = (JumpGate)station;
                _xmlWriter.WriteStartElement("targetsystem");
                _xmlWriter.WriteString(gate.TargetSystem);
                _xmlWriter.WriteFullEndElement();
                _xmlWriter.WriteStartElement("exitgateid");
                _xmlWriter.WriteString(gate.ExitGateID);
                _xmlWriter.WriteFullEndElement();

                Vector3 spawnDisposition = gate.transform.forward * 15;
                _xmlWriter.WriteStartElement("spawndisposition");
                _xmlWriter.WriteStartElement("vector3");
                _xmlWriter.WriteAttributeString("x", spawnDisposition.x.ToString());
                _xmlWriter.WriteAttributeString("y", spawnDisposition.y.ToString());
                _xmlWriter.WriteAttributeString("z", spawnDisposition.z.ToString());
                _xmlWriter.WriteEndElement();
                _xmlWriter.WriteFullEndElement();
            }


            _xmlWriter.WriteFullEndElement();
        }

        //tradelanes
        Tradelane [] tradelanes = GameObject.FindObjectsOfType <Tradelane>();
        foreach (Tradelane tl in tradelanes)
        {
            _xmlWriter.WriteStartElement("tradelane");

            _xmlWriter.WriteStartElement("id");
            _xmlWriter.WriteString(tl.ID);
            _xmlWriter.WriteFullEndElement();

            _xmlWriter.WriteStartElement("displayname");
            _xmlWriter.WriteString(tl.DisplayName);
            _xmlWriter.WriteFullEndElement();

            _xmlWriter.WriteStartElement("terminal");
            _xmlWriter.WriteString(tl.IsTerminalAorB.ToString());
            _xmlWriter.WriteFullEndElement();

            _xmlWriter.WriteStartElement("location");
            _xmlWriter.WriteStartElement("vector3");
            Vector3 disposition = tl.transform.position - origin.transform.position;
            _xmlWriter.WriteAttributeString("x", disposition.x.ToString());
            _xmlWriter.WriteAttributeString("y", disposition.y.ToString());
            _xmlWriter.WriteAttributeString("z", disposition.z.ToString());
            _xmlWriter.WriteEndElement();
            _xmlWriter.WriteFullEndElement();

            _xmlWriter.WriteStartElement("eulerangles");
            _xmlWriter.WriteStartElement("vector3");
            _xmlWriter.WriteAttributeString("x", tl.transform.eulerAngles.x.ToString());
            _xmlWriter.WriteAttributeString("y", tl.transform.eulerAngles.y.ToString());
            _xmlWriter.WriteAttributeString("z", tl.transform.eulerAngles.z.ToString());
            _xmlWriter.WriteEndElement();
            _xmlWriter.WriteFullEndElement();

            _xmlWriter.WriteStartElement("neighbor_a");
            if (tl.NeighborToA != null)
            {
                _xmlWriter.WriteString(tl.NeighborToA.ID);
            }
            else
            {
                _xmlWriter.WriteString("NULL");
            }
            _xmlWriter.WriteFullEndElement();

            _xmlWriter.WriteStartElement("neighbor_b");
            if (tl.NeighborToB != null)
            {
                _xmlWriter.WriteString(tl.NeighborToB.ID);
            }
            else
            {
                _xmlWriter.WriteString("NULL");
            }
            _xmlWriter.WriteFullEndElement();

            foreach (StationBase neighbor in tl.NeighborStations)
            {
                _xmlWriter.WriteStartElement("navneighbor");
                _xmlWriter.WriteString(neighbor.ID);
                _xmlWriter.WriteFullEndElement();
            }

            _xmlWriter.WriteFullEndElement();
        }



        _xmlWriter.WriteFullEndElement();
        _xmlWriter.Close();
    }
Пример #15
0
    public StarSystem GenerateSystemScene(string id)
    {
        string         path   = Application.dataPath + "/GameData/StarSystem/" + id + ".xml";
        StarSystemData system = LoadStarSystemData(path, true);

        StarSystem starSystem = new StarSystem(system.ID, system.DisplayName);

        RenderSettings.skybox       = Resources.Load <Material>(system.SkyboxName);
        RenderSettings.ambientLight = system.AmbientColor;
        starSystem.AmbientColor     = system.AmbientColor;


        foreach (SunData sunData in system.Suns)
        {
            GameObject sunObject = GameObject.Instantiate(Resources.Load(sunData.ID)) as GameObject;
            sunObject.name = sunData.ID;
            Sun sun = sunObject.GetComponent <Sun>();
            sun.transform.position   = sunData.Location.RealPos;
            sun.transform.localScale = sunData.Scale;
            sun.Sunlight.color       = sunData.Color;
            sun.Sunlight.intensity   = sunData.Intensity;
            starSystem.Suns.Add(sun);
        }

        foreach (PlanetData planetData in system.Planets)
        {
            GameObject planetObject = GameObject.Instantiate(Resources.Load(planetData.ID)) as GameObject;
            planetObject.name = planetData.ID;
            Planet planet = planetObject.GetComponent <Planet>();
            planet.transform.position   = planetData.Location.RealPos;
            planet.transform.localScale = planetData.OriginalScale;
            planet.OriginalScale        = planetData.OriginalScale;
            starSystem.Planets.Add(planet);
        }

        foreach (StationData stationData in system.Stations)
        {
            GameObject stationObject = GameObject.Instantiate(Resources.Load(stationData.ID)) as GameObject;
            stationObject.name = stationData.ID;
            StationBase station = stationObject.GetComponent <StationBase>();
            station.transform.position    = stationData.Location.RealPos;
            station.transform.eulerAngles = stationData.EulerAngles;
            starSystem.Stations.Add(station);
        }

        foreach (JumpGateData jumpGateData in system.JumpGates)
        {
            GameObject stationObject = GameObject.Instantiate(Resources.Load("JumpGate")) as GameObject;
            stationObject.name = jumpGateData.ID;
            JumpGate gate = stationObject.GetComponent <JumpGate>();
            gate.ID = jumpGateData.ID;
            gate.transform.position    = jumpGateData.Location.RealPos;
            gate.transform.eulerAngles = jumpGateData.EulerAngles;
            gate.TargetSystem          = jumpGateData.TargetSystem;
            gate.ExitGateID            = jumpGateData.ExitGateID;
            starSystem.Stations.Add(gate);
        }

        foreach (TradelaneData tradelaneData in system.Tradelanes)
        {
            GameObject tlObject = GameObject.Instantiate(Resources.Load("Tradelane")) as GameObject;
            tlObject.name = tradelaneData.ID;
            Tradelane tl = tlObject.transform.Find("TradelaneBody").GetComponent <Tradelane>();
            tlObject.transform.position    = tradelaneData.Location.RealPos;
            tlObject.transform.eulerAngles = tradelaneData.EulerAngles;
            tl.ID             = tradelaneData.ID;
            tl.DisplayName    = tradelaneData.DisplayName;
            tl.IsTerminalAorB = tradelaneData.IsTerminalAorB;
            tl.NeighborAID    = tradelaneData.NeighborAID;
            tl.NeighborBID    = tradelaneData.NeighborBID;
            tl.NeighborToA    = null;
            tl.NeighborToB    = null;
            starSystem.Tradelanes.Add(tl);
        }

        //now assign neighbors to tradelanes
        List <Tradelane> tradelanes = starSystem.Tradelanes;

        foreach (Tradelane tl in tradelanes)
        {
            foreach (Tradelane neighbor in tradelanes)
            {
                if (tl.NeighborAID == neighbor.ID)
                {
                    tl.NeighborToA = neighbor;
                }

                if (tl.NeighborBID == neighbor.ID)
                {
                    tl.NeighborToB = neighbor;
                }
            }
        }

        return(starSystem);
    }
        public override void UpdateBeforeSimulation10()
        {
            if (LcdPanel == null)
            {
                return;
            }

            LcdPanel.ShowPublicTextOnScreen();

            if (!NetworkTransmitter.IsSinglePlayerOrServer() ?? true)
            {
                return;
            }

            if (Station == null)
            {
                Station = Load();
                if (Station != null)
                {
                    StationManager.Register(this);
                }
            }

            // if no energy do nothing
            if (!LcdPanel.IsFunctional || !LcdPanel.IsWorking || !LcdPanel.Enabled || Station == null)
            {
                return;
            }

            const double refreshTime = 1f;

            try
            {
                if (DateTime.Now.Subtract(_lastSaved).TotalSeconds > 10f)
                {
                    Save(Station);
                }

                if (DateTime.Now.Subtract(_lastProductionUpdate).TotalSeconds < refreshTime)
                {
                    return;
                }

                Station.HandleProdCycle();
                _lastProductionUpdate = DateTime.Now;
                LcdOutput.UpdateLcdOutput(LcdPanel, Station);

                IMyCubeGrid grid = (IMyCubeGrid)LcdPanel.GetTopMostParent();
                if (grid == null)
                {
                    return;
                }
                List <IMySlimBlock> cargoBlockList = new List <IMySlimBlock>();
                grid.GetBlocks(
                    cargoBlockList,
                    slimBlock => slimBlock?.FatBlock != null &&
                    slimBlock.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_CargoContainer) &&
                    LcdPanel.CubeGrid.EntityId ==
                    slimBlock.FatBlock.CubeGrid.EntityId              // only station container
                    );

                Station.HandleCargo(cargoBlockList);
            }
            catch (Exception ex)
            {
                MyAPIGateway.Utilities.ShowNotification($"Error: {ex.Message}\n{ex.StackTrace}");
            }
        }
Пример #17
0
    /*
     * private void ShiftShield(bool isToFront)
     * {
     *      if(PlayerShip.Shield != null && PlayerShip.Shield.Type == ShieldType.Fighter)
     *      {
     *              FighterShield shield = (FighterShield)PlayerShip.Shield;
     *              float frontPortion = shield.FrontCapacity / shield.TotalCapacity;
     *              float totalAmount = shield.FrontAmount + shield.RearAmount;
     *              if(isToFront)
     *              {
     *                      frontPortion = Mathf.Clamp01(frontPortion + 0.1f);
     *
     *              }
     *              else
     *              {
     *                      frontPortion = Mathf.Clamp01(frontPortion - 0.1f);
     *
     *              }
     *
     *              shield.FrontCapacity = shield.TotalCapacity * frontPortion;
     *              shield.RearCapacity = shield.TotalCapacity * (1 - frontPortion);
     *              shield.FrontAmount = totalAmount * frontPortion;
     *              shield.RearAmount = totalAmount * (1 - frontPortion);
     *      }
     * }
     */

    private void SelectObject()
    {
        GameManager.Inst.UIManager.HUDPanel.OnClearSelectedObject();

        SelectedObjectType type = SelectedObjectType.Unknown;
        GameObject         go   = GameManager.Inst.CursorManager.SelectObject(out type);

        TargetShip = null;

        if (go != null)
        {
            GameManager.Inst.SoundManager.UI.PlayOneShot(GameManager.Inst.SoundManager.GetClip("Select"));

            if (type == SelectedObjectType.Unknown)
            {
                //attempt to figure out what it is

                StationBase station = go.GetComponent <StationBase>();
                if (station != null)
                {
                    SelectedObjectType = SelectedObjectType.Station;
                    SelectedObject     = station;
                    GameManager.Inst.UIManager.HUDPanel.OnSelectPlanetOrStation(station.transform, station.DisplayName);
                    return;
                }

                StationComponent stationComp = go.GetComponent <StationComponent>();
                if (stationComp != null)
                {
                    SelectedObjectType = SelectedObjectType.Station;
                    SelectedObject     = stationComp.ParentStation;
                    GameManager.Inst.UIManager.HUDPanel.OnSelectPlanetOrStation(stationComp.ParentStation.transform, stationComp.ParentStation.DisplayName);
                    return;
                }

                Planet planet = go.GetComponent <Planet>();
                if (planet != null)
                {
                    SelectedObjectType = SelectedObjectType.Planet;
                    SelectedObject     = planet;
                    GameManager.Inst.UIManager.HUDPanel.OnSelectPlanetOrStation(planet.transform, planet.DisplayName);
                    return;
                }
            }
            else if (type == SelectedObjectType.Ship)
            {
                ShipBase ship = go.GetComponent <ShipBase>();
                if (ship != null)
                {
                    SelectedObjectType = SelectedObjectType.Ship;
                    SelectedObject     = ship;
                    GameManager.Inst.UIManager.HUDPanel.OnSelectShip(ship);
                    TargetShip = ship;
                    return;
                }
            }
        }
        else
        {
            GameManager.Inst.UIManager.HUDPanel.OnClearSelectedObject();
        }
    }
 public FactoryStationOutput(StationBase station) : base(station)
 {
 }
Пример #19
0
 public StoredStation(StationBase runtimeStation) : base(runtimeStation)
 {
 }
 public DefaultOutput(StationBase station)
 {
     Station = station;
 }
Пример #21
0
    public override BTResult Process()
    {
        if (!MyAI.IsDocked || MyAI.MyShip.DockedStationID == "")
        {
            if (_undockSession == null)
            {
                //Debug.Log("BTUndock: Not docked!");
                return(Exit(BTResult.Fail));
            }
            else
            {
                //Debug.Log("BTUndock: success! " + MyAI.MyShip.name);
                //check if all members of the party have undocked
                if (MyAI.MyShip == MyParty.SpawnedShipsLeader)
                {
                    bool allUndocked = true;
                    foreach (ShipBase ship in MyParty.SpawnedShips)
                    {
                        //Debug.Log("docked station id " + ship.DockedStationID + " ship = " + ship.name);
                        if (ship != MyAI.MyShip && ship.DockedStationID != "")
                        {
                            allUndocked = false;
                        }
                    }
                    if (allUndocked)
                    {
                        MyParty.DockedStationID = "";
                        MyParty.PrevNode        = MyParty.NextNode;
                        MyParty.NextTwoNodes.Clear();
                        Debug.LogError("All party has undocked! " + MyAI.MyShip.name);
                        return(Exit(BTResult.Success));
                    }
                    else
                    {
                        return(Running());
                    }
                }
                else
                {
                    return(Exit(BTResult.Success));
                }
            }
        }

        StationBase station = GameManager.Inst.WorldManager.CurrentSystem.GetStationByID(MyParty.NextNode.ID);

        if (_undockSession == null)
        {
            DockRequestResult result = station.Undock(MyAI.MyShip, out _undockSession);
            if (result == DockRequestResult.Deny)
            {
                Debug.Log("BTUndock: Failed to undock");
                return(Exit(BTResult.Fail));
            }
            else
            {
                //Debug.Log("BTUndock: running");
                return(Running());
            }
        }
        else
        {
            //Debug.Log("BTUndock: running");
            return(Running());
        }
    }
        private StationBase Load()
        {
            if (LcdPanel == null)
            {
                return(null);
            }

            string stationData = LcdPanel.CustomData;

            if (!string.IsNullOrWhiteSpace(stationData) && stationData.Trim().StartsWith("<?xml"))
            {
                var tagEndOffset = stationData.IndexOf("?>", StringComparison.Ordinal);
                try
                {
                    if (stationData.IndexOf(Definitions.Version, tagEndOffset + 1, 400, StringComparison.Ordinal) == -1)
                    {
                        Log(
                            "The persisted station definition was in an old format. (" +
                            LcdPanel.CustomName +
                            ") Station will be reset to defaults!"
                            );
                        LcdPanel.CustomData = string.Empty;
                        throw new InvalidOperationException("Old format");
                    }

                    //The SE XMLSerializer wont detect the subclass needed by parsing XML, thus we need to specify the type!
                    if (stationData.IndexOf("<TradeStation", tagEndOffset + 1, 40, StringComparison.Ordinal) != -1)
                    {
                        return(MyAPIGateway.Utilities.SerializeFromXML <TradeStation>(stationData));
                    }

                    if (stationData.IndexOf("<IronForge", tagEndOffset + 1, 40, StringComparison.Ordinal) != -1)
                    {
                        return(MyAPIGateway.Utilities.SerializeFromXML <IronForge>(stationData));
                    }

                    if (stationData.IndexOf("<MiningStation", tagEndOffset + 1, 40, StringComparison.Ordinal) != -1)
                    {
                        return(MyAPIGateway.Utilities.SerializeFromXML <MiningStation>(stationData));
                    }
                }
                catch (InvalidOperationException e)
                {
                    Log("ERROR deserializing: " + e.Message);
                }
            }

            try
            {
                StationBase station = StationBase.Factory(LcdPanel.BlockDefinition.SubtypeId); //, LcdPanel.OwnerId);
                //Log("Found:" + station.Type);
                return(station);
            }
            catch (ArgumentException)
            {
                //Log("StationTypeError: Name the Block is not expected: " + LcdPanel.BlockDefinition.SubtypeId);
                // just wait for correct name
            }

            return(null);
        }