AlloyMUSH-1.1/conf/
AlloyMUSH-1.1/misc/
AlloyMUSH-1.1/scripts/
AlloyMUSH-1.1/vms/
/* powers.c
 * code for powers, except unparse_power (in unparse.c)
 */

#include "copyright.h"
#include "autoconf.h"

#include "externs.h"
#include "command.h"
#include "flags.h"

/* find_power: returns a nametab entry corresponding to a power name
 * e.g., find_power("change_quotas") returns one for POW_CHG_QUOTAS
 * by Alloy [4-1-95]
 */

NAMETAB *
find_power(name)
    char *name;
{
    char *cp;
    
    for (cp = name; *cp; cp++)
    	*cp = ToLower(*cp);
    return (NAMETAB *) hashfind(name, &mudstate.powers_htab);
}

/* do_power: grant and ungrant powers */

void
do_power(player, cause, key, arg1, arg2)
    dbref player, cause;
    int key;
    char *arg1, *arg2;
{
    char *p = arg2;
    dbref thing;
    NAMETAB *power;
    int clear = 0;
    
    /* find victim */
    init_match(player, arg1, NOTYPE);
    match_everything(0);
    thing = noisy_match_result();
    if (thing == NOTHING)
    	return;
    
    if (!Controls(player, thing)) {
    	notify_quiet(player, "Permission denied.");
    	return;
    }
    
    /* what power do we want? */
    if (*p == NOT_TOKEN) {
    	clear++;
    	p++;
    }
    
    power = find_power(p);
    if (power == NULL) {
    	notify(player, "That isn't a valid power.");
    	return;
    }
    
    if (!check_access(player, power->perm)) {
    	notify(player, "Permission denied.");
    	return;
    }
    
    /* do it */
    if (clear)
    	Powers(thing) &= ~power->flag;
    else
    	Powers(thing) |= power->flag;
    notify(player, clear ? "Cleared." : "Set.");
}

void
NDECL(init_powertab)
{
    NAMETAB *fp;
    char *nbuf, *np, *bp;
    
    hashinit(&mudstate.powers_htab, 40);
    nbuf = alloc_sbuf("init_powerstab");
    for (fp = powers_nametab; fp->name; fp++) {
    	for (np = nbuf, bp = (char *) fp->name; *bp; np++, bp++)
    	    *np = ToLower(*bp);
    	*np = '\0';
    	hashadd(nbuf, (int *) fp, &mudstate.powers_htab);
    }
    free_sbuf(nbuf);
}

void 
decompile_powers(player, thing, thingname)
    dbref player, thing;
    char *thingname;
{
    FLAG f1;
    NAMETAB *fp;

    /* Report generic flags */

    f1 = Powers(thing);

    for (fp = powers_nametab; fp->name; fp++) {

	/* Skip if we shouldn't decompile this flag, er... power */

	if (fp->perm & CA_NO_DECOMP)
	    continue;

	/* Skip if this flag is not set */

	if (!(f1 & fp->flag))
	    continue;

	/* Skip if we can't see this flag */

	if (!check_access(player, fp->perm))
	    continue;

	/* We made it this far, report this flag */

	notify(player, tprintf("@power %s=%s", thingname, fp->name));
    }
}