private bool printThisLoc(TextWriter writer, Location location) { // remember we've exported this location writer.WriteLine("part {0}", location.ExportName); writer.WriteLine(); // 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.WriteLine(" It is in {0}.", RegionsInExportOrder.Find(p => p.Region.RegionName == location.Room.Region).ExportName); } else { writer.WriteLine(); } writer.WriteLine(); // extra blank line for formatting and so utterly blank rooms don't throw an error in Inform IDE if (location.Room.IsStartRoom) { writer.Write("The player is in {0}.", location.ExportName); writer.WriteLine(); } var exportedThings = false; foreach (var thing in location.Things) { exportedThings = true; var thingText = string.Empty; if (!thing.IsPerson) { thingText += $"{getArticle(thing)}{thing.ExportName} "; } thingText += $"{whatItIs(thing)}"; if (thing.Container == null) { thingText += $" in {thing.Location.ExportName}."; } else { if (thing.Container.IsPerson) { if (thing.Worn) { thingText += $" worn by {thing.Container.ExportName}."; } else { thingText += $" carried by {thing.Container.ExportName}."; } } else { if (thing.PartOf) { thingText += $" part of {thing.Container.ExportName}."; } else { thingText += $" in {thing.Container.ExportName}."; } } } writer.Write(thingText); 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 (!string.IsNullOrWhiteSpace(thing.WarningText)) { writer.WriteLine($"[Note: there were errors with your bracketed definitions.\n{thing.WarningText}]"); } } if (exportedThings) { writer.WriteLine(); } var exportedExits = false; // export the chosen exits from this location. foreach (var direction in Directions.AllDirections) { var exit = location.GetBestExit(direction); if (exit != null && exit.Exported == false) { // remember we've exported this exit exit.Exported = true; exportedExits = true; if (exit.Door == null) { writeNormalExit(writer, location, direction, exit); } else { writeDoor(writer, location, direction, exit); } } } if (exportedExits) { writer.WriteLine(); } var wroteConditionalExit = false; foreach (var direction in Directions.AllDirections) { var exit = location.GetBestExit(direction); if (exit != null && exit.Conditional) { wroteConditionalExit = true; writer.WriteLine("Instead of going {0} from {1}, block conditional exits.", getInform7Name(direction).ToLowerInvariant(), location.ExportName); } } if (wroteConditionalExit) { writer.WriteLine(); } return(wroteConditionalExit); }
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(); } }