Exemplo n.º 1
0
        public CrewRoute(
            string originBody,
            string originBiome,
            string destinationBody,
            string destinationBiome,
            int economyBerths,
            int luxuryBerths,
            double duration,
            string flightNumber,
            IRegistryCollection depotRegistry)
        {
            if (economyBerths + luxuryBerths < 1)
            {
                throw new RouteInsufficientPayloadException();
            }
            EconomyBerths    = economyBerths;
            LuxuryBerths     = luxuryBerths;
            OriginBody       = originBody;
            OriginBiome      = originBiome;
            DestinationBody  = destinationBody;
            DestinationBiome = destinationBiome;
            FlightNumber     = flightNumber;
            FlightStatus     = FlightStatus.Boarding;
            UniqueId         = Guid.NewGuid().ToString("N");
            Duration         = Math.Max(duration, KSPUtil.dateTimeFormatter.Day);

            OriginDepot      = depotRegistry.GetDepot(originBody, originBiome);
            DestinationDepot = depotRegistry.GetDepot(destinationBody, destinationBiome);
        }
Exemplo n.º 2
0
        public void OnLoad(ConfigNode node)
        {
            ArrivalTime      = double.Parse(node.GetValue(nameof(ArrivalTime)));
            DestinationBiome = node.GetValue(nameof(DestinationBiome));
            DestinationBody  = node.GetValue(nameof(DestinationBody));
            Duration         = double.Parse(node.GetValue(nameof(Duration)));
            EconomyBerths    = int.Parse(node.GetValue(nameof(EconomyBerths)));
            if (!node.HasValue(nameof(FlightNumber)))
            {
                FlightNumber = _registry.GetNewFlightNumber();
            }
            else
            {
                FlightNumber = node.GetValue(nameof(FlightNumber));
            }
            LuxuryBerths = int.Parse(node.GetValue(nameof(LuxuryBerths)));
            OriginBiome  = node.GetValue(nameof(OriginBiome));
            OriginBody   = node.GetValue(nameof(OriginBody));
            if (!node.HasValue(nameof(UniqueId)))
            {
                UniqueId = Guid.NewGuid().ToString("N");
            }
            else
            {
                UniqueId = node.GetValue(nameof(UniqueId));
            }

            if (node.HasNode(PASSENGERS_NODE_NAME))
            {
                var passengersNode = node.GetNode(PASSENGERS_NODE_NAME);
                var passengerNodes = passengersNode.GetNodes();
                foreach (var passengerNode in passengerNodes)
                {
                    var passenger = new Passenger();
                    passenger.OnLoad(passengerNode);
                    Passengers.Add(passenger);
                }
                Passengers.Sort(new PassengerComparer());
            }

            // We need to reset some things if flight status can't be loaded from the config
            var flightStatus = FlightStatus.Unknown;

            if (!node.TryGetEnum(nameof(FlightStatus), ref flightStatus, FlightStatus.Unknown) ||
                flightStatus == FlightStatus.Unknown)
            {
                flightStatus = FlightStatus.Boarding;
                Passengers.Clear();
                ArrivalTime = 0d;
            }
            FlightStatus = flightStatus;

            OriginDepot      = _registry.GetDepot(OriginBody, OriginBiome);
            DestinationDepot = _registry.GetDepot(DestinationBody, DestinationBiome);
        }
Exemplo n.º 3
0
        public void ConnectToDepotEvent()
        {
            // Check for issues that would prevent deployment
            if (IsConnectedToDepot)
            {
                Messenger.DisplayMessage(ALREADY_CONNECTED_MESSAGE);
                return;
            }

            var body  = vessel.mainBody.name;
            var biome = WOLF_AbstractPartModule.GetVesselBiome(vessel);

            if (biome == string.Empty)
            {
                Messenger.DisplayMessage(Messenger.INVALID_SITUATION_MESSAGE);
                return;
            }
            if (biome.StartsWith("Orbit") && biome != "Orbit")
            {
                Messenger.DisplayMessage(Messenger.INVALID_ORBIT_SITUATION_MESSAGE);
                return;
            }
            if (!_registry.HasEstablishedDepot(body, biome))
            {
                Messenger.DisplayMessage(Messenger.MISSING_DEPOT_MESSAGE);
                return;
            }
            var otherDepotModules = vessel.FindPartModulesImplementing <WOLF_DepotModule>();

            if (otherDepotModules.Any())
            {
                Messenger.DisplayMessage(Messenger.INVALID_DEPOT_PART_ATTACHMENT_MESSAGE);
                return;
            }
            var otherWolfPartModules = vessel.FindPartModulesImplementing <WOLF_AbstractPartModule>();

            if (otherWolfPartModules.Any(p => !(p is ICorporeal)))
            {
                Messenger.DisplayMessage(Messenger.INVALID_HOPPER_PART_ATTACHMENT_MESSAGE);
                return;
            }

            // Negotiate recipes with the depot
            var depot  = _registry.GetDepot(body, biome);
            var result = depot.Negotiate(WolfRecipe);

            if (result is FailedNegotiationResult)
            {
                var failureResult = result as FailedNegotiationResult;
                foreach (var missingResource in failureResult.MissingResources)
                {
                    Messenger.DisplayMessage(string.Format(Messenger.MISSING_RESOURCE_MESSAGE, missingResource.Value, missingResource.Key));
                }
                return;
            }

            // Register hopper
            HopperId = _registry.CreateHopper(depot, WolfRecipe);

            DepotBody          = body;
            DepotBiome         = biome;
            IsConnectedToDepot = true;

            Events["ConnectToDepotEvent"].guiActive      = false;
            Events["DisconnectFromDepotEvent"].guiActive = true;

            // Hook into vessel destroyed event to release resources back to depot
            if (vessel != null)
            {
                vessel.OnJustAboutToBeDestroyed += OnVesselDestroyed;
                GameEvents.OnVesselRecoveryRequested.Add(OnVesselRecovered);
            }

            Messenger.DisplayMessage(string.Format(Messenger.SUCCESSFUL_DEPLOYMENT_MESSAGE, body));
        }
Exemplo n.º 4
0
        public override void OnStart(StartState state)
        {
            base.OnStart(state);

            if (Localizer.TryGetStringByTag("#autoLOC_USI_WOLF_HOPPER_ALREADY_CONNECTED_MESSAGE", out string alreadyConnectedMessage))
            {
                ALREADY_CONNECTED_MESSAGE = alreadyConnectedMessage;
            }
            if (Localizer.TryGetStringByTag("#autoLOC_USI_WOLF_HOPPER_DISCONNECTED_MESSAGE", out string disconnectedMessage))
            {
                DISCONNECTED_MESSAGE = disconnectedMessage;
            }
            if (Localizer.TryGetStringByTag("#autoLOC_USI_WOLF_HOPPER_LOST_CONNECTION_MESSAGE", out string lostConnectionMessage))
            {
                LOST_CONNECTION_MESSAGE = lostConnectionMessage;
            }
            if (Localizer.TryGetStringByTag("#autoLOC_USI_WOLF_HOPPER_NOT_CONNECTED_MESSAGE", out string notConnectedMessage))
            {
                NOT_CONNECTED_MESSAGE = notConnectedMessage;
            }

            if (Localizer.TryGetStringByTag("#autoLOC_USI_WOLF_CONNECT_TO_DEPOT_GUI_NAME", out string connectGuiName))
            {
                CONNECT_TO_DEPOT_GUI_NAME = connectGuiName;
            }
            if (Localizer.TryGetStringByTag("#autoLOC_USI_WOLF_DISCONNECT_FROM_DEPOT_GUI_NAME", out string disconnectGuiName))
            {
                DISCONNECT_FROM_DEPOT_GUI_NAME = disconnectGuiName;
            }

            if (Localizer.TryGetStringByTag("#autoLOC_USI_WOLF_CURRENT_BIOME_GUI_NAME", out string currentBiomeGuiName))
            {
                CURRENT_BIOME_GUI_NAME = currentBiomeGuiName;
            }
            Fields["CurrentBiome"].guiName = CURRENT_BIOME_GUI_NAME;


            Events["ConnectToDepotEvent"].guiName      = CONNECT_TO_DEPOT_GUI_NAME;
            Events["DisconnectFromDepotEvent"].guiName = DISCONNECT_FROM_DEPOT_GUI_NAME;

            // Find the WOLF scenario and parse the hopper recipe
            var scenario = FindObjectOfType <WOLF_ScenarioModule>();

            _registry = scenario.ServiceManager.GetService <IRegistryCollection>();

            ParseWolfRecipe();

            // If we were previously connected to a depot, make sure we still are
            if (IsConnectedToDepot)
            {
                var body  = vessel.mainBody.name;
                var biome = WOLF_AbstractPartModule.GetVesselBiome(vessel);
                var depot = _registry.GetDepot(DepotBody, DepotBiome);

                if (depot == null || depot.Body != body || depot.Biome != biome)
                {
                    Debug.LogWarning("[WOLF] Hopper lost connection to its depot.");
                    Messenger.DisplayMessage(LOST_CONNECTION_MESSAGE);
                    StopResourceConverter();
                    ReleaseResources();
                }
                else
                {
                    // Hook into vessel destroyed event to release resources back to depot
                    if (vessel != null)
                    {
                        vessel.OnJustAboutToBeDestroyed += OnVesselDestroyed;
                        GameEvents.OnVesselRecoveryRequested.Add(OnVesselRecovered);
                    }
                }
            }

            Events["ConnectToDepotEvent"].guiActive      = !IsConnectedToDepot;
            Events["DisconnectFromDepotEvent"].guiActive = IsConnectedToDepot;
        }