private static void positionRelativeTo(Room room, Room existing, CompassPoint existingCompassPoint, out Vector delta) { delta = CompassPointHelper.GetAutomapDirectionVector(existingCompassPoint); delta.X *= Settings.PreferredDistanceBetweenRooms + room.Width; delta.Y *= Settings.PreferredDistanceBetweenRooms + room.Height; var newRoomCenter = existing.InnerBounds.Center + delta; room.Position = Settings.Snap(new Vector(newRoomCenter.X - room.Width / 2, newRoomCenter.Y - room.Height / 2)); }
/// <summary> /// Approximately match two directions, allowing for aesthetic rearrangement by the user. /// </summary> /// <remarks> /// Two compass points match if they are on the same side of a box representing the room. /// </remarks> private static bool approximateDirectionMatch(CompassPoint one, CompassPoint two) { return(CompassPointHelper.GetAutomapDirectionVector(one) == CompassPointHelper.GetAutomapDirectionVector(two)); }
private void ProcessPromptCommand(string command) { // unless we find one, this command does not involve moving in a given direction m_lastMoveDirection = null; // first process trizbort commands if (command.ToUpper().StartsWith(m_settings.AddRegionCommand.ToUpper())) { var regionName = command.Substring(m_settings.AddRegionCommand.Length).Trim(); if (!string.IsNullOrEmpty(regionName) && m_lastKnownRoom != null) { // region already exists, just set the room to it if (Settings.Regions.Find(p => p.RegionName.Equals(regionName, StringComparison.OrdinalIgnoreCase)) == null) { Settings.Regions.Add(new Region { RegionName = regionName, TextColor = Settings.Color[Colors.Subtitle], RColor = System.Drawing.Color.White }); } m_lastKnownRoom.Region = regionName; } return; } if (command.ToUpper().StartsWith(m_settings.AddObjectCommand.ToUpper())) { // the user wants to add an object to the map var objectName = command.Substring(m_settings.AddObjectCommand.Length).Trim(); if (!string.IsNullOrEmpty(objectName) && m_lastKnownRoom != null) { if (!string.IsNullOrEmpty(m_lastKnownRoom.Objects)) { var alreadyExists = false; foreach (var line in m_lastKnownRoom.Objects.Replace("\r", string.Empty).Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries)) { if (StringComparer.InvariantCultureIgnoreCase.Compare(line.Trim(), objectName) == 0) { alreadyExists = true; break; } } if (!alreadyExists) { m_lastKnownRoom.Objects += "\r\n" + objectName; } } else { m_lastKnownRoom.Objects = objectName; } } return; } // TODO: We entirely don't handle "go east. n. s then w." etc. and I don't see an easy way of doing so. // split the command into individual words var parts = command.Split(s_wordSeparators, StringSplitOptions.RemoveEmptyEntries); if (parts.Length == 0) { // there's no command left over return; } // strip out words we consider fluff, like "to". var words = new List <string>(); foreach (var word in parts) { var stripWord = false; foreach (var strippable in s_wordsToStripFromCommands) { if (StringComparer.InvariantCultureIgnoreCase.Compare(word, strippable) == 0) { stripWord = true; break; } } if (word[0] == '[') { for (var temp = 1; temp < word.Length; temp++) { if (word[temp] == ']') { stripWord = true; break; } if ((word[temp] < '0') || (word[temp] > '9')) { break; } } } if (stripWord) { continue; } words.Add(word); } // if the command starts with a word meaning "go", remove it. if (words.Count > 0) { foreach (var wordMeaningGo in s_wordsMeaningGo) { if (StringComparer.InvariantCultureIgnoreCase.Compare(words[0], wordMeaningGo) == 0) { words.RemoveAt(0); break; } } } if ((words.Count == 2) && (words[0].Equals("trypush"))) { foreach (var pair in s_namesForMovementCommands) { var direction = pair.Key; var wordsForDirection = pair.Value; foreach (var wordForDirection in wordsForDirection) { if (StringComparer.InvariantCultureIgnoreCase.Compare(words[1], wordForDirection) == 0) { Vector delta = CompassPointHelper.GetAutomapDirectionVector(CompassPointHelper.GetCompassDirection(direction)); delta.X *= m_lastKnownRoom.Width + Settings.PreferredDistanceBetweenRooms; delta.X += m_lastKnownRoom.X; delta.Y *= m_lastKnownRoom.Height + Settings.PreferredDistanceBetweenRooms; delta.Y += m_lastKnownRoom.Y; m_lastKnownRoom.Position = Settings.Snap(delta); } } } } // look for custom tb trizbort commands if (words.Count > 0) { if (words[0].Equals("tb", StringComparison.OrdinalIgnoreCase)) { if (words.Count > 1) { if (words[1].Equals("dotted", StringComparison.OrdinalIgnoreCase)) { UseDottedConnection = true; } if (words[1].Equals("exit", StringComparison.OrdinalIgnoreCase)) { if (words.Count > 2) { var direction = getDirection(words[2]); if (direction != MappableDirection.None) { m_canvas.AddExitStub(m_lastKnownRoom, direction); } } } if (words[1].Equals("noexit", StringComparison.OrdinalIgnoreCase)) { if (words.Count > 2) { var direction = getDirection(words[2]); if (direction != MappableDirection.None) { m_canvas.RemoveExitStub(m_lastKnownRoom, direction); } } } } } } // we should have just one word left if (words.Count != 1) { // we have no words left, or more than one return; } // the word we have left is hopefully a direction var possibleDirection = words[0]; // work out which direction it is, if any foreach (var pair in s_namesForMovementCommands) { var direction = pair.Key; var wordsForDirection = pair.Value; foreach (var wordForDirection in wordsForDirection) { if (StringComparer.InvariantCultureIgnoreCase.Compare(possibleDirection, wordForDirection) == 0) { // aha, we know which direction it was m_lastMoveDirection = direction; // remove any stub exit in this direction; // we'll either add a proper connection shortly, or they player can't go that way m_canvas.RemoveExitStub(m_lastKnownRoom, m_lastMoveDirection.Value); return; } } } // the word wasn't for a direction after all. }