musicmud-2.1.6/data/
musicmud-2.1.6/data/help/
musicmud-2.1.6/data/policy/
musicmud-2.1.6/data/wild/
musicmud-2.1.6/data/world/
musicmud-2.1.6/doc/
musicmud-2.1.6/src/ident/
musicmud-2.1.6/src/lua/
musicmud-2.1.6/src/lua/include/
musicmud-2.1.6/src/lua/src/lib/
musicmud-2.1.6/src/lua/src/lua/
musicmud-2.1.6/src/lua/src/luac/
true = 1

function buildmatch(who, what)
  if getn(what)==1 and what[1]=="here" then
    return {owner(who)}
  end
  return match(who, what)
end

function pressurise(where)
  local a = getflag(where, flag.Airless)
  setflag(where, flag.Airless, 0)
  if a then
    sendr(where, "You hear the sound of an atmosphere rushing into place.")

    dotrap("pressurise", where, where)
  end

  local r = getobj(where, "room.0")
  if r then
    pressurise(r)
  end
end

function depressurise(where)
  local a = getflag(where, flag.Airless)
  local f = getflag(where, flag.OnFire)
  setflag(where, flag.Airless, 1)
  setflag(where, flag.OnFire, 0)
  if not a then
    if f then
      sendr(where, "The ^oatmosphere^n escapes, thus putting out the ^Rfire^n.")
    else
      sendr(where, "The ^oatmosphere^n escapes.")
    end

    dotrap("depressurise", where, where)

  end
  local mobs = allholdsflag(where, flag.Mobile)
  for i, o in mobs do
    if not wearsflag(o, flag.SpaceSuit) then
      kill(o, "depressurised")
    end
  end

  local r = getobj(where, "room.0")
  if r then
    depressurise(r)
  end

end

open = function(what)
  if (state(what)==0) then
    return
  end
  setstate(what, 0)
  act(what, "%1 %[opens/open].")
  local l = getobj(what, "other")
  if l then
    setstate(l, 0)
    act(l, "%1 %[opens/open].")
  end
end

close = function(what)
  if (state(what)==1) then
    return
  end
  setstate(what, 1)
  act(what,"%1 %[closes/close].")
  local l = getobj(what, "other")
  if l then
    setstate(l, 1)
    act(l, "%1 %[closes/close].")
  end
end

lock = function(what)
  if (state(what)==2) then
    return
  end
  local l = getobj(what, "other")
  if state(what)==1 then
    act(what, "%1 %[locks/lock].")
  else
    act(what, "%1 %[closes and locks/close and lock].")
  end
  setstate(what, 2)
  if l then
    if state(l)==1 then
      act(l, "%1 %[locks/lock].")
    else
      act(l, "%1 %[closes and locks/close and lock].")
    end
    setstate(l, 2)
  end
end

function curmatch(arg, n)
  
  local x = ""
  for i, v in arg do
    if i!= 0 then
      x = x .. v
    end
  end

  if tonumber(x) then
    local num = tonumber(x)
    return n, floor(tonumber(x)*getintd(n, "cur.0.value", 1))
  end  

  local s, t

  s, t = strfind(x, "([.0-9]+)") 

  if s then
    local num = tonumber(strsub(x, s, t))
    if not num then
      send(pl, "Bad number")
      return
    end

    local pre = strsub(x, 1, s-1)
    local post = strsub(x, t+1)

    if strlen(pre)>0 and strlen(post)>0 then
      return nil, "Use either a prefix or a postfix, not both."
    end

    if strlen(post)>0 then
      pre = post
    end

    for idx, n in children("nations_zone") do
      for i = 0, getintd(n, "cur.count", 0)-1 do
        for j = 0, getintd(n, "cur."..i..".count", 0)-1 do
          local a = getstr(n, format("cur.%i.%i", i, j))
          if a == pre then
            return n, floor(tonumber(num)*getintd(n, format("cur.%i.value", i), 1))
          end
        end
      end
    end
    
  end

  return nil, "What?"
end