Exemplo n.º 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);
            }
        }
Exemplo n.º 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);
        }
Exemplo n.º 3
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);
            }
            if (newPlace is DarkPlace || currentPlace is DarkPlace)
            {
                return(CreateConnection(newPlace, currentPlace));
            }
            //var newPlaceHasDuplicateExits = newPlace.exitHeadings.Where(x => !String.IsNullOrEmpty(x)).GroupBy(x => x).Any(c => c.Count() > 1);
            //var oldPlaceHasDuplicateExits = currentPlace.exitHeadings.Where(x => !String.IsNullOrEmpty(x)).GroupBy(x => x).Any(c => c.Count() > 1);
            //if (newPlaceHasDuplicateExits || oldPlaceHasDuplicateExits) {
            //    int direction = (int)Player.me.attemptedMoveDirection;
            //    int invertDirection = (int)Place.InvertExitState(Player.me.attemptedMoveDirection);
            //    //Connect backward
            //    newPlace.connectedPlaces[invertDirection] = currentPlace;
            //    newPlace.connectedPlaceHashes[invertDirection] = currentPlace.GetHashCode();
            //    //Connect forward
            //    currentPlace.connectedPlaces[direction] = newPlace;
            //    currentPlace.connectedPlaceHashes[direction] = newPlace.GetHashCode();
            //    //Set up grid ref by backward connection
            //    var newGridRef = currentPlace.GetOffsetGridRef((Place.ExitDirections)direction);
            //    newPlace.PlaceGridRef = newGridRef;
            //    return true;
            //} else {

            //For every exit in the current place
            var numExitDirections = Enum.GetValues(typeof(WoTParser.Place.ExitDirections)).Length;

            for (int i = 0; i < numExitDirections; i++)
            {
                //find the direction of the new place.
                if (currentPlace.exitHeadings[i] == newPlace.heading)
                {
                    //if the direction of the new place, aims back at the old place
                    var j = (int)Place.InvertExitState((Place.ExitDirections)i);
                    if (newPlace.exitHeadings[j] == currentPlace.heading)
                    {
                        return(CreateConnection(newPlace, currentPlace));
                    }
                }
            }
            //}

            Debug.LogError("Could not connect places " + currentPlace + " " + newPlace);
            return(false);
        }