コード例 #1
0
        //create a
        public ShipPlacement PlaceShip(PlacementRequest request)
        {
            if (_currentShipIndex > 4)
            {
                throw new Exception("You cannot add another ship, 5 is the limit!");
            }
            if (!isValidCoordinate(request.Coordinate))
            {
                return(ShipPlacement.NotEnoughSpace);
            }

            Ship newShip = ShipCreation.CreateShip(request.SelectedShip);

            switch (request.Direction)
            {
            case ShipDirection.Down:
                return(PlaceShipDown(request.Coordinate, newShip));

            case ShipDirection.Up:
                return(PlaceShipUp(request.Coordinate, newShip));

            case ShipDirection.Right:
                return(PlaceShipRight(request.Coordinate, newShip));

            default:
                return(PlaceShipLeft(request.Coordinate, newShip));
            }
        }
コード例 #2
0
 /// <summary>Draws the portion of the GUI that displays the user's confimation of action button and handles its selection.</summary>
 /// <param name="haveKerbals">A value indicating whether any buttons for selecting a kerbal have been drawn.</param>
 /// <param name="haveLocations">A value indicating whether any buttons for selecting a location have been drawn.</param>
 private void DrawActionButton(bool haveKerbals, bool haveLocations)
 {
     if (haveKerbals && haveLocations)
     {
         if (_selectedKerbal == null || _selectedLocation == null)
         {
             GUILayout.Label(string.Format(
                                 "Select a {0}{1}",
                                 _selectedKerbal == null ? "kerbal" : "location",
                                 _selectedKerbal == null && _selectedLocation == null ? " and a location" : string.Empty),
                             _elementStyles.InvalidLabel);
         }
         else
         {
             if (GUILayout.Button($"Place {_selectedKerbal.name} outside {_selectedLocation.LocationName}", _elementStyles.SelectedButton))
             {
                 RequestedPlacement =
                     new PlacementRequest
                 {
                     Kerbal   = _selectedKerbal,
                     Location = _selectedLocation,
                     Items    = _itemsSelected[_selectedKerbal.name],
                 };
                 "PlacementRequest created - deactivating GUI".Debug();
                 IsActive        = false;
                 _selectedKerbal = null;
             }
         }
     }
     else
     {
         GUILayout.Label(haveKerbals ? "No locations found" : "No available kerbals", _elementStyles.InvalidLabel);
     }
 }
コード例 #3
0
 private static void AddVesselToGame(PlacementRequest request, ConfigNode vesselNode)
 {
     $"{request.Kerbal.name} is being placed at {request.Location.LocationName}".Log();
     ScreenMessages.PostScreenMessage(new ScreenMessage($"{request.Kerbal.name} is being placed at {request.Location.LocationName}", 4.0f, ScreenMessageStyle.UPPER_LEFT));
     HighLogic.CurrentGame.AddVessel(vesselNode);
     request.Kerbal.rosterStatus = ProtoCrewMember.RosterStatus.Assigned;
     HighLogic.CurrentGame.CrewRoster[request.Kerbal.name].rosterStatus = ProtoCrewMember.RosterStatus.Assigned;
 }
コード例 #4
0
 private static void AllocateInventoryItems(PlacementRequest request)
 {
     WalkAboutPersistent.AllocatedItems.Remove(request.Kerbal.name);
     if (request.Items.Count > 0)
     {
         WalkAboutPersistent.AllocatedItems.Add(request.Kerbal.name, new List <string>());
         foreach (var item in request.Items)
         {
             AllocateInventoryItem(request.Kerbal.name, item);
         }
     }
 }
コード例 #5
0
        private static Orbit CreateOrbitForKerbal(PlacementRequest request)
        {
            var pos =
                Homeworld.GetWorldSurfacePosition(
                    request.Location.Coordinates.Latitude,
                    request.Location.Coordinates.Longitude,
                    request.Location.Coordinates.Altitude);
            var orbit = new Orbit(0, 0, 0, 0, 0, 0, 0, Homeworld);

            orbit.UpdateFromStateVectors(pos, Homeworld.getRFrmVel(pos), Homeworld, Planetarium.GetUniversalTime());
            $"created orbit for {Homeworld.name}".Debug();
            return(orbit);
        }
コード例 #6
0
 private static void SetVesselLocation(PlacementRequest request, ConfigNode vesselNode)
 {
     vesselNode.SetValue("sit", Vessel.Situations.LANDED.ToString());
     vesselNode.SetValue("landed", true.ToString());
     vesselNode.SetValue("splashed", false.ToString());
     vesselNode.SetValue("lat", request.Location.Coordinates.Latitude.ToString());
     vesselNode.SetValue("lon", request.Location.Coordinates.Longitude.ToString());
     vesselNode.SetValue("alt", request.Location.Coordinates.Altitude.ToString());
     vesselNode.SetValue("hgt", "0.28");
     vesselNode.SetValue("nrm", $"{request.Location.Normal.x},{request.Location.Normal.y},{request.Location.Normal.z}");
     vesselNode.SetValue("rot", $"{request.Location.Rotation.x},{request.Location.Rotation.y},{request.Location.Rotation.z},{request.Location.Rotation.w}");
     "adjusted vesselNode location".Debug();
 }
コード例 #7
0
        /// <summary>
        /// Adds a kerbal to the game the requested location.
        /// </summary>
        internal static void PlaceKerbal(PlacementRequest request)
        {
            $"{request.Kerbal.name} will be placed outside {request.Location.LocationName}".Debug();
            $"placement lat:{request.Location.Coordinates.Latitude} long:{request.Location.Coordinates.Longitude} alt:{request.Location.Coordinates.Altitude}".Debug();
            var orbit      = CreateOrbitForKerbal(request);
            var vesselNode = CreateVesselNode(request, orbit);

            SetVesselLocation(request, vesselNode);
            AddVesselToGame(request, vesselNode);

            AllocateInventoryItems(request);

            AllocateEvaResources(vesselNode);
        }
コード例 #8
0
ファイル: SetupWorkflow.cs プロジェクト: nikolasclay/Project
        private Board BuildBoard(string playerName)
        {
            //create new board instance

            Board board = new Board();

            //loop through the list of ships from smallest to largest and prompt the user for placement

            for (ShipType s = ShipType.Destroyer; s <= ShipType.Carrier; s++)
            {
                bool isValidPlacement = false;
                do
                {
                    PlacementRequest request = new PlacementRequest();

                    //Get coordinates from user and store in request.coordinate package
                    request.Coordinate = ConsoleInput.GetCoordinates();

                    //request ship direction from user
                    request.Direction = ConsoleInput.GetDirection();

                    //send all ship types in the request package
                    request.SelectedShip = s;

                    //pass the request package to the PlaceShip() method in the Board class
                    var result = board.PlaceShip(request);

                    //Add conditions that will trigger messages if placement rules are broken

                    if (result == ShipPlacement.Overlap)
                    {
                        ConsoleOutput.OverLapMsg(playerName);
                    }
                    else if (result == ShipPlacement.NotEnoughSpace)
                    {
                        ConsoleOutput.NotEnoughSpaceMsg(playerName);
                    }
                    else
                    {
                        ConsoleOutput.OK(playerName);
                        isValidPlacement = true;
                    }
                } while (!isValidPlacement);
            }
            return(board);
        }
コード例 #9
0
        private static ConfigNode CreateVesselNode(PlacementRequest request, Orbit orbit)
        {
            // create an id for the flight object that will represent the kerbal's EVA
            var genderQualifier = request.Kerbal.gender == ProtoCrewMember.Gender.Female ? "female" : string.Empty;
            var flightId        = ShipConstruction.GetUniqueFlightID(HighLogic.CurrentGame.flightState);

            $"created flightId {flightId}".Debug();

            // create a ship consisting of just the kerbal - this is how EVAs are represented in KSP
            var partNodes = new ConfigNode[1];

            partNodes[0] =
                ProtoVessel.CreatePartNode($"kerbalEVA{genderQualifier}", flightId, request.Kerbal);
            "created partNodes".Debug();
            var vesselNode = ProtoVessel.CreateVesselNode(request.Kerbal.name, VesselType.EVA, orbit, 0, partNodes);

            "created vesselNode".Debug();
            return(vesselNode);
        }