// Seeing as LPC is a MUD programming language, a lot
// depends on the mudlib. This example is based on the
// MorgenGrauen mudlib available at ftp://mg.mud.de
//
// There's probably simpler ways of doing this, but this
// way demonstrates the use of closures.
//
// mapping keys are case-insensitive for some awkward reason
// and seeing as this is only for demonstration purposes, it
// will convert upper and lower-case letters to the lower-case
// rot13-equivalent to keep matters simple.

#pragma strict_types

#include <properties.h>

inherit "std/room";

mapping map;

void init() {
  ::init();

  map = mkmapping(efun::explode("abcdefghijklmnopqrstuvwxyz", ""),
                     efun::explode("nopqrstuvwxyzabcdefghijklm", ""));
}

void create() {
  ::create();

  SetProp(P_INT_SHORT, "Rot13");
  SetProp(P_INT_LONG, "Use 'rot13 <string>'\n");
  SetProp(P_LIGHT, 1);
  SetProp(P_INDOORS, 1);

  AddCmd("rot13", "rot13", 1);
}

int rot13(string str) {
  string *arr;

  if(!str) return 0;

  arr = efun::explode(str, "");

  map_array(arr, lambda( ({ 'x, 'y }),
    ({ #'write,
      ({ #'?, ({ #'member, 'y, 'x }), ({ #'[, 'y, 'x }), 'x }) }) ), map);
  write("\n");

  return 1;
}
