untermud/DOC/
untermud/DOC/U/
untermud/DOC/U/U-examples/
untermud/DOC/internals/
untermud/DOC/wizard/
untermud/MISC/
untermud/MISC/dbchk/
untermud/RWHO/
untermud/RWHO/rwhod/
/*
    Copyright (C) 1991, Marcus J. Ranum. All rights reserved.
*/

#include    "config.h"
#include    "mud.h"
#include    "match.h"
#include    "vars.h"

extern int cmd_take (int ac, char *av[], char *who, char *aswho);

static int stop_using(char *who, char *ud);

static int stop_using(char *who, char *ud)
{
  if (ut_listadd (who, who, var_cont, ud))
    return (UERR_FATAL);
  if (ut_unset (who, who, var_using))
    return (UERR_FATAL);

  say (who, "You stop holding ", ut_name (ud), ".\n", (char *) 0);
  return (UERR_NONE);
}


/* ARGSUSED */
int cmd_use (int ac, char *av[], char *who, char *aswho)
{
  char *ud;

  ud = ut_getatt (who, 0, typ_obj, var_using, (char *) 0);

  /* no args stop using */
  if (ac <= 1) {
    if (ud == (char *) 0) {
      say (who, "You aren't holding anything.\n", (char *) 0);
      return (UERR_NONE);
    }
    return (stop_using (who, ud));
  } else if (ac == 2) {
    char ob[MAXOID];
    int xx;

    if (ud != (char *) 0 && (xx = stop_using (who, ud)) != UERR_NONE)
      return (xx);
    if (matchinv (who, av[1], 0, MTCH_UNIQ | MTCH_QUIET, ob) &&
      matchinv (who, av[1], 0, MTCH_FRST | MTCH_QUIET, ob)) {
      if ((xx = cmd_take (ac, av, who, aswho)) != UERR_NONE)
        return (xx);
      if (matchinv (who, av[1], 0, MTCH_UNIQ | MTCH_QUIET, ob) &&
        matchinv (who, av[1], 0, MTCH_FRST | MTCH_QUIET, ob))
        return (UERR_NOMATCH);
    }
    if (ut_listdel (who, who, var_cont, ob))
      return (UERR_FATAL);
    if (ut_set (who, who, typ_obj, var_using, ob))
      return (UERR_FATAL);
    say (who, "You are now holding ", ut_name (ob), ".\n", (char *) 0);
    return (UERR_NONE);
  }

  say (who, "You can only use one thing at a time.\n", (char *) 0);
  return (UERR_NONE);
}