예제 #1
0
        public static int BentConnections(bool ignoreAnnos)
        {
            return(Project.Current.Elements.OfType <Connection>().Count(p => {
                var port1 = (Room.CompassPort)p.VertexList[0].Port;
                var port2 = (Room.CompassPort)p.VertexList[1].Port;

                if (port1 == null || port2 == null)
                {
                    return false;
                }

                var firstRoomConnectionDir = port1.CompassPoint;
                var secondRoomConnectionDir = port2.CompassPoint;

                if (ignoreAnnos)
                {
                    return !Project.Current.Canvas.EqualEnough(firstRoomConnectionDir, CompassPointHelper.GetOpposite(secondRoomConnectionDir));
                }
                if (p.VertexList[0].Connection.StartText != "" || p.VertexList[1].Connection.EndText != "")
                {
                    return false;
                }

                // if the port directions are not (roughly) opposite, then we have a bent connection. Note NN(EW) = N, WW(NS) = W, etc.
                return !Project.Current.Canvas.EqualEnough(firstRoomConnectionDir, CompassPointHelper.GetOpposite(secondRoomConnectionDir));
            }
                                                                        ));
        }
예제 #2
0
        private void writeDoor(TextWriter writer, Location location, AutomapDirection direction, Exit exit)
        {
            var oppositeDirection = CompassPointHelper.GetOpposite(direction);
            var reciprocal        = exit.Target.GetBestExit(oppositeDirection);

            writer.WriteLine($"{exit.ConnectionName} is a door. {exit.ConnectionName} is {direction.ToString().ToLower()} of {location.ExportName} and {oppositeDirection.ToString().ToLower()} of {exit.Target.ExportName}.  ");
            writer.WriteLine($"{exit.ConnectionName} is {(exit.Door.Open ? "open" : "closed")} and {(exit.Door.Openable ? "openable" : "not openable")}.");
            writer.WriteLine($"{exit.ConnectionName} is {(exit.Door.Locked ? "locked" : "unlocked")} and {(exit.Door.Lockable ? "lockable" : "not lockable")}.");
            writer.WriteLine($"The description of {exit.ConnectionName} is {toInform7PrintableString(exit.ConnectionDescription)}.");
            reciprocal.Exported = true;
            writer.WriteLine();
        }
예제 #3
0
 /// <summary>
 ///   Test whether an exit is reciprocated in the other direction; i.e. is there a bidirectional connection.
 /// </summary>
 public static bool IsReciprocated(Location source, AutomapDirection direction, Location target)
 {
     if (target != null)
     {
         var oppositeDirection = CompassPointHelper.GetOpposite(direction);
         var reciprocal        = target.GetBestExit(oppositeDirection);
         if (reciprocal != null)
         {
             Debug.Assert(reciprocal.PrimaryDirection == oppositeDirection || reciprocal.SecondaryDirection == oppositeDirection, "Alleged opposite direction appears to lead somewhere else. Something went wrong whilst building the set of exits from each room.");
             return(reciprocal.Target == source);
         }
     }
     return(false);
 }
예제 #4
0
        private void writeDoor(TextWriter writer, Location location, MappableDirection direction, Exit exit)
        {
            var oppositeDirection = CompassPointHelper.GetOpposite(direction);
            var reciprocal        = exit.Target.GetBestExit(oppositeDirection);

            writer.WriteLine("Object {0} {1}", GetExportName(exit.ConnectionName, null), exit.ConnectionDescription);
            writer.WriteLine("  with  name {0},", toI6Words(Deaccent(stripUnaccentedCharacters(exit.ConnectionName))));
            writer.WriteLine("        description {0},", toI6String(exit.ConnectionDescription, DOUBLE_QUOTE));
            writer.WriteLine("        found_in {0} {1},", location.ExportName, exit.Target.ExportName);
            writer.WriteLine("        door_to [; if (self in {0}) return {1}; return {0};],", location.ExportName, exit.Target.ExportName);
            writer.WriteLine("        door_dir [; if (self in {0}) return {1}; return {2}; ],", location.ExportName, toI6PropertyName(direction), toI6PropertyName(oppositeDirection));
            writer.WriteLine("  has   door {0} {1} {2} {3} ;", exit.Door.Openable ? "openable" : string.Empty, exit.Door.Open ? "open" : "~open", exit.Door.Lockable ? "lockable" : string.Empty, exit.Door.Locked ? "locked" : "~locked");
            reciprocal.Exported = true;
            writer.WriteLine();
        }
예제 #5
0
        private static void writeNormalExit(TextWriter writer, Location location, AutomapDirection direction, Exit exit)
        {
            writer.Write($"{getInform7Name(direction)} of {location.ExportName} is {exit.Target.ExportName}.");
            var oppositeDirection = CompassPointHelper.GetOpposite(direction);

            if (Exit.IsReciprocated(location, direction, exit.Target))
            {
                // only export each connection once, if reciprocated;
                // I7 will infer that the direction is two way unless contradicted.
                var reciprocal = exit.Target.GetBestExit(oppositeDirection);
                reciprocal.Exported = true;
            }
            else if (exit.Target.GetBestExit(oppositeDirection) == null)
            {
                // if we aren't laying down a contradiction which I7 will pick up,
                // then be clear about one way connections.
                writer.Write($" {getInform7Name(oppositeDirection)} of {exit.Target.ExportName} is nowhere.");
            }
            writer.WriteLine();
        }
예제 #6
0
        protected override void ExportContent(TextWriter writer)
        {
            // export location
            bool needConditionalFunction = false, wroteConditionalFunction = false;

            foreach (var location in LocationsInExportOrder)
            {
                location.Exported = true;

                writer.WriteLine();
                writer.WriteLine($"<ROOM {location.ExportName}");
                writer.WriteLine($"    (DESC {toZILString(location.Room.Name)})");
                writer.Write($"    (IN ROOMS)");

                if (!string.IsNullOrWhiteSpace(location.Room.PrimaryDescription))
                {
                    writer.WriteLine();
                    writer.Write($"    (LDESC {toZILString(location.Room.PrimaryDescription)})");
                }

                foreach (var direction in AllDirections)
                {
                    var exit = location.GetBestExit(direction);
                    if (exit != null && exit.Conditional)
                    {
                        writer.WriteLine();
                        writer.Write($"    ({toZILPropertyName(direction)} PER TRIZBORT-CONDITIONAL-EXIT)");
                        needConditionalFunction = true;
                    }
                    else if (exit != null)
                    {
                        writer.WriteLine();
                        writer.Write($"    ({toZILPropertyName(direction)} TO {exit.Target.ExportName})");
                        var oppositeDirection = CompassPointHelper.GetOpposite(direction);
                        if (Exit.IsReciprocated(location, direction, exit.Target))
                        {
                            var reciprocal = exit.Target.GetBestExit(oppositeDirection);
                            reciprocal.Exported = true;
                        }
                    }
                }

                if (!location.Room.IsDark)
                {
                    writer.WriteLine();
                    writer.Write("    (FLAGS LIGHTBIT)");
                }
                writer.WriteLine(">");
                writer.WriteLine();

                if (needConditionalFunction && !wroteConditionalFunction)
                {
                    writer.WriteLine();
                    writer.WriteLine("<ROUTINE TRIZBORT-CONDITIONAL-EXIT ()");
                    writer.WriteLine($"    <TELL {DOUBLE_QUOTE}An export nymph appears on your keyboard. She says, 'You can't go that way, as that exit was marked as conditional, you know, a dotted line, in Trizbort. Obviously in your game you'll have a better rationale for this than, er, me.' She looks embarrassed. 'Bye!'{DOUBLE_QUOTE} CR>");
                    writer.WriteLine("    <RFALSE>>");
                    writer.WriteLine();
                    wroteConditionalFunction = true;
                }

                exportThings(writer, location.Things, null, 1);
            }
        }
예제 #7
0
        protected override void ExportContent(TextWriter writer)
        {
            // export regions
            foreach (var region in RegionsInExportOrder)
            {
                writer.WriteLine("There is a region called {0}.", getExportName(region.ExportName, null));
                writer.WriteLine();
            }

            // export each location
            foreach (var location in LocationsInExportOrder)
            {
                // remember we've exported this location
                location.Exported = true;

                // tiresome format, avoids I7 errors:
                // these can occur with rooms called "West of House", or one room called "Cave" and one called "Damp Cave", etc.
                writer.Write("There is a room called {0}.", location.ExportName);
                if (location.ExportName != location.Room.Name)
                {
                    writer.Write(" The printed name of it is {0}.", toInform7PrintableString(location.Room.Name));
                }
                var description = location.Room.PrimaryDescription;
                if (!string.IsNullOrEmpty(description))
                {
                    writer.Write(" {0}{1}", toInform7PrintableString(description), description.EndsWith(".") ? string.Empty : ".");
                }
                if (location.Room.IsDark)
                {
                    writer.Write(" It is dark.");
                }

                if (!string.IsNullOrEmpty(location.Room.Region) && !location.Room.Region.Equals(Region.DefaultRegion))
                {
                    writer.Write(" It is in {0}.", RegionsInExportOrder.Find(p => p.Region.RegionName == location.Room.Region).ExportName);
                }

                writer.WriteLine(); // end the previous line
                writer.WriteLine(); // blank line
            }

            // export the chosen exits from each location.
            foreach (var location in LocationsInExportOrder)
            {
                // export the chosen exits from this location.
                foreach (var direction in AllDirections)
                {
                    var exit = location.GetBestExit(direction);
                    if (exit != null && !exit.Exported)
                    {
                        // remember we've exported this exit
                        exit.Exported = true;

                        writer.Write("{0} of {1} is {2}.", getInform7Name(direction), location.ExportName, exit.Target.ExportName);
                        var oppositeDirection = CompassPointHelper.GetOpposite(direction);
                        if (Exit.IsReciprocated(location, direction, exit.Target))
                        {
                            // only export each connection once, if reciprocated;
                            // I7 will infer that the direction is two way unless contradicted.
                            var reciprocal = exit.Target.GetBestExit(oppositeDirection);
                            reciprocal.Exported = true;
                        }
                        else if (exit.Target.GetBestExit(oppositeDirection) == null)
                        {
                            // if we aren't laying down a contridiction which I7 will pick up,
                            // then be clear about one way connections.
                            writer.Write(" {0} of {1} is nowhere.", getInform7Name(oppositeDirection), exit.Target.ExportName);
                        }
                        writer.WriteLine();
                    }
                }
            }

            writer.WriteLine();

            // if an exit is conditional, block it.
            var wroteConditionalFunction = false;

            foreach (var location in LocationsInExportOrder)
            {
                foreach (var direction in AllDirections)
                {
                    var exit = location.GetBestExit(direction);
                    if (exit != null && exit.Conditional)
                    {
                        if (!wroteConditionalFunction)
                        {
                            writer.WriteLine("To block conditional exits:");
                            writer.WriteLine("\tsay \"An export nymph appears on your keyboard. She says, 'You can't go that way, as that exit was marked as conditional, you know, a dotted line, in Trizbort. Obviously in your game you'll have a better rationale for this than, er, me.' She looks embarrassed. 'Bye!'\"");
                            writer.WriteLine();
                            wroteConditionalFunction = true;
                        }

                        writer.WriteLine("Instead of going {0} from {1}, block conditional exits.", getInform7Name(direction).ToLowerInvariant(), location.ExportName);
                    }
                }
            }

            if (wroteConditionalFunction)
            {
                // add a blank line if we need one
                writer.WriteLine();
            }

            var exportedThings = false;

            foreach (var location in LocationsInExportOrder)
            {
                foreach (var thing in location.Things)
                {
                    exportedThings = true;
                    if (thing.Container == null)
                    {
                        writer.Write("{0}{1} {2} in {3}.", getArticle(thing.ExportName), thing.ExportName, isAre(thing.ExportName), thing.Location.ExportName);
                    }
                    else
                    {
                        writer.Write("{0}{1} {2} in the {3}.", getArticle(thing.ExportName), thing.ExportName, isAre(thing.ExportName), thing.Container.ExportName);
                    }
                    if (thing.DisplayName != thing.ExportName)
                    {
                        writer.Write(" It is privately-named. The printed name of it is {0}{1} Understand {2} as {3}.", toInform7PrintableString(thing.DisplayName), thing.DisplayName.EndsWith(".") ? string.Empty : ".", toInform7UnderstandWords(thing.DisplayName), thing.ExportName);
                    }
                    writer.WriteLine();
                }
            }

            if (exportedThings)
            {
                // add a blank line if we need one
                writer.WriteLine();
            }
        }