dmuck0.15-beta/docs/muf/
dmuck0.15-beta/game/
dmuck0.15-beta/game/logs/
dmuck0.15-beta/game/muf/
dmuck0.15-beta/game/muf/text/
/* FLAG STUFF */
#include "config.h"
#include "params.h"
#include "db.h"
#include "interface.h"
#include "externs.h"
#include "mush.h"

/*  Flag name,  letter,  Type,       FLAG    */
FLAG flag_table[] =
{
  { "ABODE",		'A', 	TYPE_ROOM,	ABODE},
#ifdef MUSH
  { "AUDIBLE", 		'a',	NOTYPE,		AUDIBLE},
#endif
  { "AUTOSTART",	'A', 	TYPE_EXIT,	ABODE},
  { "AUTHOR",		'A', 	TYPE_PLAYER,	ABODE},
  { "BUILDER",		'B', 	NOTYPE,		BUILDER},
  { "CHOWN_OK",		'C',	NOTYPE,		CHOWN_OK},
  { "DARK", 		'D', 	NOTYPE, 	DARK},
  { "DEBUG",		'D',	TYPE_PROGRAM,	DARK},
  { "ENTER_OK",		'e',	NOTYPE,		ENTER_OK},
  { "GOD",		'G',	NOTYPE,		GOD},
#ifdef MUSH
  { "HALT", 		'H',    TYPE_THING,	HAVEN},
#endif
  { "HAVEN", 		'H', 	NOTYPE, 	HAVEN},
  { "HEARING", 		'H',    TYPE_EXIT,	HAVEN},
  { "INTERACTIVE",	'I',	TYPE_PLAYER,	INTERACTIVE},
  { "JUMP_OK", 		'J', 	NOTYPE, 	JUMP_OK},
  { "LINK_OK", 		'L', 	NOTYPE, 	LINK_OK},
  { "MONITOR",		'M',	TYPE_PLAYER,	MUCKER},
  { "MUCKER",		'M',	TYPE_PLAYER,	MUCKER},
#ifdef MUSH
  { "NOCOMMAND",	'n',	NOTYPE,		NOCOMMAND}, 
#endif
  { "NOSPOOF",		'N',	TYPE_PLAYER,	NOSPOOF},
#ifdef MUSH
  { "PUPPET",		'p',	TYPE_THING,	PUPPET},
#endif
  { "QUELL",   		'Q',	NOTYPE,		QUELL},
  { "SAFE",		's',	NOTYPE,		SAFE},
  { "SETUID",		'S',	TYPE_PROGRAM,	STICKY},
  { "SILENT",		'S',	TYPE_PLAYER,	STICKY},
  { "STICKY",		'S',	NOTYPE,		STICKY},
  { "UNFINDABLE",	'U',	NOTYPE,		UNFIND},
  { "VERBOSE",		'V',	NOTYPE,		VERBOSE},
  { "VISUAL",		'v',	NOTYPE,		VISUAL},
  { "WIZARD",		'W', 	NOTYPE, 	WIZARD},
};

#ifdef MUSH
void decompile_flags(dbref player, dbref thing, char *objct)
{
  char hold ='\0';
  int i;

  if(FLAGS(thing) & ~TYPE_MASK)
  {
    /* print flags */
  for (i = 0; i < sizeof(flag_table) / sizeof(FLAG); i++) {
    if(FLAGS(thing) & (flag_table[i].flag)  &&
      (Typeof(thing) == flag_table[i].type || 
      flag_table[i].type == NOTYPE) && hold != flag_table[i].letter)  {
      notify(player, player, tprintf("@set %s=%s", objct, flag_table[i].name));
      hold = (flag_table[i].letter);
      }
    }
  }
}
#endif

char *unparse_flags(dbref thing)
{
  static char buf[BUFFER_LEN];
  char *type_codes = "R-EPFG*";
  char *p;
  char hold = '\0';
  int command_num;
  
  p = buf;
  if(Typeof(thing) != TYPE_THING) *p++ = type_codes[Typeof(thing)];
  if(FLAGS(thing) & ~TYPE_MASK)
  {
    /* print flags */
  for (command_num = 0; command_num < sizeof(flag_table) / sizeof(FLAG); 
       command_num++) {
    if(FLAGS(thing) & (flag_table[command_num].flag)  &&
      (Typeof(thing) == flag_table[command_num].type || 
      flag_table[command_num].type == NOTYPE) && hold 
       != flag_table[command_num].letter)  {
      *p++ = (flag_table[command_num].letter);
      hold = (flag_table[command_num].letter);
      }
    }
  }
  *p = '\0';
  return buf;
}

int strn_cmp(char *sub, char *string)
{
  if(!*sub || !*string) return 0;
  if(!strncasecmp(sub, string, strlen(sub))) return 1;
  return 0;
}

FLAG *flag_lookup(char *name, dbref thing)
{
 int command_num;
   
  for (command_num = 0;
      (command_num < sizeof(flag_table) / sizeof(FLAG)) &&
      (stringn_compare(name, flag_table[command_num].name,
      strlen(name)) > 0); command_num++);
   if ((command_num < sizeof(flag_table) / sizeof(FLAG)) &&
      (!stringn_compare(name, flag_table[command_num].name, strlen(name))) &&
      (Typeof(thing) == flag_table[command_num].type || 
      flag_table[command_num].type == NOTYPE))
        return(&flag_table[command_num]);
  return NULL;
}

#ifdef MUSH
int convert_flags(player, s, p_mask, p_toggle, p_type)
     dbref player;
     char *s;
     object_flag_type *p_mask;
     object_flag_type *p_toggle;
     object_flag_type *p_type;
{
  FLAG *f;
  object_flag_type mask, toggle, type;
  int done;
  mask = toggle = 0;
  type = NOTYPE;

  while (s && *s) {

    done = 0;

    switch (*s) {
    case 'P':
      type = TYPE_PLAYER;
      break;
    case 'R':
      type = TYPE_ROOM;
      break;
    case 'E':
      type = TYPE_THING;
      break;
    default:

      /* check generic flags first */
      for (f = flag_table; !done; f++) {
	if (*s == f->letter) {
	  mask |= f->flag;
	  done = 1;
	}
      }

/*
      if (!done && (type != NOTYPE))
	while ((f->type != type) && (f->type != NOTYPE))
	  f++;

      for ( ; !done && (f->type != NOTYPE); f++) {
	if (*s == f->letter) {
	  if (type == NOTYPE) {
	    type = f->type;
	    toggle |= f->flag;
	    done = 1;
	  } else if (type != f->type) {
	    notify(player, player, 
                   tprintf("Type conflict with flag '%c'.", *s));
	    return 0;
	  }
	}
      }
*/
      /* if we get this far and still haven't found anything, error. */
      if (!done) {
	notify(player, player, tprintf("%c: unknown flag.", *s));
	return 0;
      }
    }
    s++;
  }

  *p_mask = mask;
  *p_toggle = toggle;
  *p_type = type;
  return 1;
}
#endif

void do_list_flags(__DO_PROTO)
{
  int i;
  char buff[BUFFER_LEN];
  char *bp;
  bp = buff;

    safe_str("Flags:", buff, &bp);
    for (i = 0; i < sizeof(flag_table) / sizeof(FLAG); i++) {
    safe_chr(' ', buff, &bp);
    safe_str(flag_table[i].name, buff, &bp);
  }
  *bp = '\0';

  notify(player, player, buff);
}