示例#1
0
        private static bool CreateConnection(Place newPlace, Place currentPlace)
        {
            int direction       = (int)Player.me.attemptedMoveDirection;
            int invertDirection = (int)Place.InvertExitState(Player.me.attemptedMoveDirection);
            //Set up grid ref by backward connection
            var newGridRef = currentPlace.GetOffsetGridRef((Place.ExitDirections)direction);

            if (!World.places.Any(p => p.gridRefX == newGridRef.x && p.gridRefZ == newGridRef.z))
            {
                newPlace.PlaceGridRef = newGridRef;
                //Connect backward
                newPlace.connectedPlaces[invertDirection]      = currentPlace;
                newPlace.connectedPlaceHashes[invertDirection] = currentPlace.GetHashCode();
                //Connect forward
                currentPlace.connectedPlaces[direction]      = newPlace;
                currentPlace.connectedPlaceHashes[direction] = newPlace.GetHashCode();
                return(true);
            }
            else
            {
                var conflictingPlace = World.places.Single(p => p.gridRefX == newGridRef.x && p.gridRefZ == newGridRef.z);
                Debug.LogWarning("Something already at " + conflictingPlace.PlaceGridRef + " called " + conflictingPlace.heading + ". Refusing to make connection.");
                return(false);
            }
        }
示例#2
0
        public static bool ConnectPlaces(ref Place newPlace, ref Place currentPlace)
        {
            //Don't bother connecting a place to itself
            if (newPlace.placeHash == currentPlace.placeHash)
            {
                return(true);
            }
            //Don't connect places with ambiguous exit direcions
            string currentPlaceHeading = currentPlace.heading;

            if (newPlace.exitHeadings.Where(e => e == currentPlaceHeading).Count() > 1)
            {
                //UnityEngine.Debug.LogWarning(newPlace.heading + " has multiple exits named " + currentPlace.heading
                //    + ", direction can not be determined");
                return(false);
            }
            //Connect this location to the last
            Place.ExitDirections direction = Place.ExitDirections.North;
            foreach (string newExitHeading in newPlace.exitHeadings)
            {
                //If there is an exit in this direcion
                if (newExitHeading != null)
                {
                    Console.WriteLine(newExitHeading + " " + currentPlace.heading);
                    //And its name matches our last new location
                    if (newExitHeading.Contains(currentPlace.heading))
                    {
                        //TODO: Check that the last direction moved matches this heading also.
                        //Connect these two places
                        Console.WriteLine("Connected " + newPlace.heading + " to "
                                          + currentPlace.heading, ConsoleColor.Yellow);
                        //Connect backward
                        int directionIntBackward = (int)direction;
                        newPlace.connectedPlaces[directionIntBackward]      = currentPlace;
                        newPlace.connectedPlaceHashes[directionIntBackward] = currentPlace.GetHashCode();
                        //Connect forward
                        int directionIntForward = (int)Place.InvertExitState(direction);
                        currentPlace.connectedPlaces[directionIntForward]      = newPlace;
                        currentPlace.connectedPlaceHashes[directionIntForward] = newPlace.GetHashCode();

                        //Set up grid ref
                        newPlace.PlaceGridRef = currentPlace.GetOffsetGridRef(direction);

                        return(true);//Connection created, stop processing.
                    }
                }
                direction = (Place.ExitDirections)(int)(direction + 1);
            }
            Console.WriteLine("Unable to connect given places " + newPlace.heading
                              + " and " + currentPlace.heading, ConsoleColor.Red);
            return(false);
        }