znmud-0.0.1/benchmark/
znmud-0.0.1/cmd/
znmud-0.0.1/cmd/emotes/
znmud-0.0.1/cmd/objects/
znmud-0.0.1/cmd/tiny/
znmud-0.0.1/doc/
znmud-0.0.1/farts/
znmud-0.0.1/lib/
znmud-0.0.1/lib/combat/
znmud-0.0.1/lib/core/bodytypes/
znmud-0.0.1/lib/engine/
znmud-0.0.1/lib/farts/
znmud-0.0.1/logs/
#
# file::    cmd_rlink.rb

# This source code copyright (C) 2009 Craig Smith
# All rights reserved.
#
# Released under the terms of the TeensyMUD Public License
# See LICENSE file for additional information.
#

module Cmd

  bindtextdomain("cmd")

  # Links two room exits together
  def cmd_rlink(args)
	case args
	when /(\d+)\s+(\d+)\s+(\S+)\s+(\S+)/ # Creates new exits and links them
	  room1 = get_object($1.to_i)
	  room2 = get_object($2.to_i)
   	  ex_name1 = $3.downcase
      	  ex_name2 = $4.downcase
	  if not room1.is_a? Room or not room2.is_a? Room
		sendto _("Both arguments must be room numbers.")
	  else
   	      # These are just for simplicity and speed
	      ex_name1 = "east" if ex_name1 == "e"
	      ex_name1 = "west" if ex_name1 == "w"
	      ex_name1 = "north" if ex_name1 == "n"
	      ex_name1 = "south" if ex_name1 == "s"
	      ex_name1 = "up" if ex_name1 == "u"
	      ex_name1 = "down" if ex_name1 == "d"
	      ex_name2 = "east" if ex_name2 == "e"
	      ex_name2 = "west" if ex_name2 == "w"
	      ex_name2 = "north" if ex_name2 == "n"
	      ex_name2 = "south" if ex_name2 == "s"
	      ex_name2 = "up" if ex_name2 == "u"
	      ex_name2 = "down" if ex_name2 == "d"
	      e1 = Exit.new(ex_name1, id, room1.id, room2.id)
	      room1.exits << e1.id
	      e2 = Exit.new(ex_name2, id, room2.id, room1.id)
	      room2.exits << e2.id
	      e1.linked_exit = e2.id
	      e2.linked_exit = e1.id
	      put_object(e1)
	      put_object(e2)
	      sendto _("Linked.")
	   end
	when /(\d+)\s+(\d+)/  # Exits exists but are not linked yet...
	  room1 = get_object($1.to_i)
	  room2 = get_object($2.to_i)
	  if not room1.is_a? Room or not room2.is_a? Room
		sendto _("Both arguments must be room numbers.")
	  else
		firstexit = nil
		room1.exits.each do |exid|
			ex = get_object(exid)
			firstexit = ex if ex.to_room == room2.id
		end
		if not firstexit
			sendto _("Room %{num1} does not have an exit to Room %{num2}" % {:num1 => room1.id, :num2 => room2.id})
		else
			secondexit = nil
			room2.exits.each do |exid|
				ex = get_object(exid)
				secondexit = ex if ex.to_room == room1.id
			end
			if not secondexit
				sendto _("Room %{num1} does not have an exit to Room %{num2}" % {:num1 => room2.id, :num2 => room1.id})
			else
				firstexit.linked_exit = secondexit.id
				secondexit.linked_exit = firstexit.id
				secondexit.door_state = firstexit.door_state
				secondexit.door_name = firstexit.door_name
				secondexit.attributes = firstexit.attributes
				secondexit.required_key = firstexit.required_key if firstexit.required_key
				sendto _("Rooms successfully linked.")
			end
		end
	  end
	else
		sendto _("Usage: rlink room1# room2#. Ex: room 23 45")
	end
  end

end