powers.c
TinyMAZE/src/maze/powers.c · 12.6 KB
From the archive TinyMAZEv2.5a.tar.gz
Download the archive « Back to the archive contents
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include "db.h"
#include "powers.h"
#include "externs.h"
#define NO PW_NO
#define YES PW_YES
#define YESLT PW_YESLT
#define YESEQ PW_YESEQ
/* You can define powers in any order that you wish, so long as the *
* POW_<power> matches the power it's meant for. There must be *
* NUM_POWS elements in the array. */
/* The first line of each power structure defines the level of power *
* the player of said class will have when initially @classed. The *
* second line shows how powerful that power can get for that class. *
* *
* Ovrld Advsr Leadr Knght Guard Squir Adven Psnt Wrkr Lamb */
struct pow_list powers[NUM_POWS] =
{
{
"Announce", POW_ANNOUNCE, "Ability to @announce for free",
{YES, YES, YES, YES, YES, NO, NO, NO, NO, NO },
{YES, YES, YES, YES, YES, YES, NO, NO, NO, NO }
},
{
"Backstage", POW_BACKSTAGE, "Ability to see numbers on all objects",
{YES, YES, YES, NO, YES, NO, NO, NO, NO, NO },
{YES, YES, YES, YES, YES, YES, NO, NO, NO, NO }
},
{
"Beep", POW_BEEP, "Abililty to use %a substitution",
{YES, YES, YES, YES, YES, YES, NO, NO, NO, NO },
{YES, YES, YES, YES, YES, YES, YES, NO, NO, NO }
},
{
"Boot", POW_BOOT, "Ability to @boot players off the game",
{YESLT, YESLT, NO, NO, NO, NO, NO, NO, NO, NO },
{YESEQ, YESEQ, YESEQ, YESEQ, YESEQ, YESEQ, NO, NO, NO, NO }
},
{
"Broadcast", POW_BROADCAST, "Ability to @broadcast a message",
{YES, YES, NO, NO, NO, NO, NO, NO, NO, NO },
{YES, YES, YES, NO, NO, NO, NO, NO, NO, NO }
},
{
"Channel", POW_CHANNEL, "Ability to join any channel, no NO_COM flag",
{YES, NO, NO, NO, NO, NO, NO, NO, NO, NO },
{YES, YES, YES, YES, YES, YES, YES, NO, NO, NO }
},
{
"Chown", POW_CHOWN, "Ability to change ownership of an object",
{YESEQ, YESEQ, NO, YESLT, NO, NO, NO, NO, NO, NO },
{YESEQ, YESEQ, YESEQ, YESEQ, YESLT, YESEQ, NO, NO, NO, NO }
},
{
"Class", POW_CLASS, "Ability to re@classify somebody",
{YESLT, NO, NO, NO, NO, NO, NO, NO, NO, NO },
{YESLT, NO, NO, NO, NO, NO, NO, NO, NO, NO }
},
{
"Database", POW_DB, "Ability to use various database utilities",
{YES, YES, NO, NO, NO, NO, NO, NO, NO, NO },
{YES, YES, YES, NO, NO, NO, NO, NO, NO, NO }
},
{
"Examine", POW_EXAMINE, "Ability to see people's homes and locations",
{YESEQ, YESEQ, YESLT, YESEQ, YESEQ, NO, NO, NO, NO, NO },
{YES, YESEQ, YESEQ, YESEQ, YESEQ, YESEQ, NO, NO, NO, NO }
},
{
"Free", POW_FREE, "Ability to build, etc. for free",
{YES, YES, YES, NO, NO, NO, NO, NO, NO, NO },
{YES, YES, YES, YES, YES, YES, YES, YES, NO, NO }
},
{
"Functions", POW_FUNCTIONS, "Ability to get correct results from all functions",
{YES, YES, YES, NO, NO, NO, NO, NO, NO, NO },
{YES, YES, YES, YES, YES, YES, NO, YES, NO, NO }
},
{
"Hostnames", POW_HOST, "Ability to see hostnames on the WHO list",
{YES, YES, NO, NO, NO, NO, NO, NO, NO, NO },
{YES, YES, YES, YESEQ, YESLT, YES, YESEQ, NO, NO, NO }
},
{
"Join", POW_JOIN, "Ability to 'join' players",
{YESEQ, YESEQ, YESLT, YESLT, YES, NO, NO, NO, NO, NO },
{YES, YES, YES, YESEQ, YES, YES, NO, YES, NO, NO }
},
{
"Misc", POW_MISC, "Ability to use miscellaneous commands",
{NO, NO, NO, NO, NO, NO, NO, NO, NO, NO },
{YES, YES, YES, NO, NO, NO, NO, NO, NO, NO }
},
{
"Modify", POW_MODIFY, "Ability to modify other people's objects",
{YESLT, YESLT, YESLT, YESLT, NO, NO, NO, NO, NO, NO },
{YESEQ, YESEQ, YESEQ, YESEQ, YESEQ, YESEQ, YESEQ, NO, NO, NO }
},
{
"Money", POW_MONEY, "Power to have INFINITE money",
{YES, YES, NO, NO, NO, NO, NO, NO, NO, NO },
{YES, YES, YES, NO, NO, YES, NO, YES, NO, NO }
},
{
"Newpasswd", POW_NEWPASS, "Ability to use the @newpassword command",
{YESLT, YESLT, NO, NO, NO, NO, NO, NO, NO, NO },
{YESEQ, YESLT, YESLT, NO, NO, NO, NO, NO, NO, NO }
},
{
"Noquota", POW_NOQUOTA, "Power to have INFINITE quota",
{YES, YES, NO, NO, NO, NO, NO, NO, NO, NO },
{YES, YES, YES, YES, YES, YES, YES, YES, NO, NO }
},
{
"Nuke", POW_NUKE, "Power to @nuke other characters",
{YESLT, NO, NO, NO, NO, NO, NO, NO, NO, NO },
{YESLT, YESLT, NO, NO, NO, NO, NO, NO, NO, NO }
},
{
"Pcreate", POW_PCREATE, "Power to create new characters",
{YES, NO, NO, NO, NO, NO, NO, NO, NO, NO },
{YES, YES, NO, NO, NO, NO, NO, NO, NO, NO }
},
{
"Queue", POW_QUEUE, "Power to see everyone's commands in the queue",
{YES, YES, YES, NO, NO, NO, NO, NO, NO, NO },
{YES, YES, YES, YES, YES, YES, YES, NO, NO, NO }
},
{
"Security", POW_SECURITY, "Ability to do various security-related things",
{YES, NO, NO, NO, NO, NO, NO, NO, NO, NO },
{YES, NO, NO, NO, NO, NO, NO, NO, NO, NO }
},
{
"Seeatr", POW_SEEATR, "Ability to see attributes on other people",
{YESEQ, YESEQ, YESLT, YESLT, YESLT, NO, NO, NO, NO, NO },
{YESEQ, YESEQ, YESEQ, YESEQ, YESEQ, YESLT, NO, NO, NO, NO }
},
{
"Setpow", POW_SETPOW, "Ability to alter people's powers",
{YESLT, NO, NO, NO, NO, NO, NO, NO, NO, NO },
{YESLT, NO, NO, NO, NO, NO, NO, NO, NO, NO }
},
{
"Setquota", POW_SETQUOTA, "Ability to change people's quotas",
{YESLT, NO, NO, NO, NO, NO, NO, NO, NO, NO },
{YESEQ, YESLT, NO, NO, NO, NO, NO, NO, NO, NO }
},
{
"Shutdown", POW_SHUTDOWN, "Ability to @shutdown the game",
{YES, NO, NO, NO, NO, NO, NO, NO, NO, NO },
{YES, YES, NO, NO, NO, NO, NO, NO, NO, NO }
},
{
"Slave", POW_SLAVE, "Ability to set the slave flag",
{YESLT, YESLT, NO, NO, NO, NO, NO, NO, NO, NO },
{YESLT, YESLT, YESLT, YESLT, YESLT, NO, NO, NO, NO, NO }
},
{
"Spoof", POW_SPOOF, "Ability to do unlimited @emit etc",
{YES, YES, NO, NO, NO, NO, NO, NO, NO, NO },
{YES, YES, YES, YES, NO, YES, YES, YES, NO, NO }
},
{
"Steal", POW_STEAL, "Ability to give negative amounts of gold",
{YES, YES, YES, NO, NO, NO, NO, NO, NO, NO },
{YES, YES, YES, YES, YES, YES, NO, YES, NO, NO }
},
{
"Summon", POW_SUMMON, "Ability to 'summon' other players",
{YESEQ, YESEQ, YESLT, YESLT, YESLT, NO, NO, NO, NO, NO },
{YESEQ, YESEQ, YESEQ, YESEQ, YESEQ, YESLT, NO, NO, NO, NO }
},
{
"Teleport", POW_TELEPORT, "Ability to use unlimited @tel",
{YES, YES, NO, NO, NO, NO, NO, NO, NO, NO },
{YES, YES, YES, NO, NO, NO, NO, YES, NO, NO }
},
{
"Who", POW_WHO, "Ability to see hidden players on the WHO list",
{YES, YES, YESLT, NO, NO, NO, NO, NO, NO, NO },
{YES, YES, YES, YES, YESEQ, NO, NO, NO, NO, NO }
},
{
"WizAttrs", POW_WATTR, "Ability to set WIZARD attributes",
{YES, YES, NO, NO, NO, NO, NO, NO, NO, NO },
{YES, YES, YES, YES, NO, NO, NO, YES, NO, NO }
},
{
"WizFlags", POW_WFLAGS, "Ability to set WIZARD flags",
{YES, YES, NO, NO, NO, NO, NO, NO, NO, NO },
{YES, YES, YES, NO, NO, NO, NO, YES, NO, NO }
},
{
"UNUSED", POW_UNUSED, "Unused power",
{NO, NO, NO, NO, NO, NO, NO, NO, NO, NO },
{NO, NO, NO, NO, NO, NO, NO, NO, NO, NO }
},
{
"UNUSED2", POW_UNUSED, "Unused power",
{NO, NO, NO, NO, NO, NO, NO, NO, NO, NO },
{NO, NO, NO, NO, NO, NO, NO, NO, NO, NO }
}
};
#undef NO
#undef YES
#undef YESLT
#undef YESEQ
int get_pow(OBJ *player, int pow)
{
if(is_root(player))
return(PW_YES);
if(Typeof(player) != TYPE_PLAYER)
if(!(player->flags & INHERIT_POWERS))
return(PW_NO);
if(!player->pows) /* This should only happen if it's not a player */
return(PW_NO);
return(player->pows[powers[pow].num]);
}
int has_pow(OBJ *player, OBJ *recipt, int pow)
{
int pows;
if(is_root(player))
return(1);
if(IS(player, TYPE_PLAYER, PLAYER_MORTAL))
return(0);
if(player->flags & INHERIT_POWERS)
player = player->owner;
pows = get_pow(player, pow);
if((pows == PW_YES) ||
(!recipt && (pows == PW_YESLT || pows == PW_YESEQ)) ||
(pows == PW_YESLT && get_class(recipt) < get_class(player)) ||
(pows == PW_YESEQ && get_class(recipt) <= get_class(player)))
return(1);
return(0);
}
void set_pow(OBJ *player, int pow, int val)
{
if(!player->pows)
return;
if(val != PW_YES && val != PW_YESEQ && val != PW_YESLT && val != PW_NO)
return;
player->pows[powers[pow].num] = val;
}
int name_to_pow(char *powstr)
{
int k;
for(k = 0;k < NUM_POWS;++k)
if(!string_compare(powers[k].name, powstr))
return(k);
return(-1);
}
char *pow_to_name(int pow)
{
if(pow < 0 || pow >= NUM_POWS)
return(NULL);
return(powers[pow].name);
}
void do_powcount(OBJ *player, char *pwr)
{
OBJ *o;
int ctr = 0;
char *level = "";
int k, m;
if(!*pwr)
{
notify(player, "You must specify a power to check.");
return;
}
if((k = name_to_pow(pwr)) < 0)
{
notify(player, tprintf("Unknown power: %s", pwr));
return;
}
for(o = player_list;o;o = o->next)
if(controls(player, o, POW_EXAMINE) && !is_root(o))
{
switch(m = get_pow(o, k))
{
case PW_YES:
level = "YES";
break;
case PW_YESEQ:
level = "YESEQ";
break;
case PW_YESLT:
level = "YESLT";
break;
case PW_NO:
break;
}
if(m != PW_NO)
{
notify(player,
tprintf("%s |+W|- |+B|%s", unparse_object(player, o), level));
ctr++;
}
}
if(!ctr)
notify(player, tprintf("No one has the power of %s.", pwr));
else
notify(player, tprintf("%d player%s have the power of %s.",
ctr, check_plural(ctr, "", "s"), pwr));
}
void do_powers(OBJ *player, char *whostr)
{
OBJ *who;
int k, ctr = 0;
int m;
char *l = "";
if(!*whostr)
who = player;
else
{
who = match_object(player, whostr, TYPE_PLAYER);
if(!who)
{
notify(player, no_match(whostr));
return;
}
}
if(Typeof(who) != TYPE_PLAYER || !who->pows)
{
notify(player, "Only players have powers.");
return;
}
if(!controls(player, who, POW_EXAMINE) && !(who->flags & VISIBLE))
{
notify(player, perm_denied());
return;
}
for(k = 0;k < NUM_POWS;k++)
{
m = get_pow(who, k);
switch(m)
{
case PW_YES:
l = "";
break;
case PW_YESLT:
l = ":LT";
break;
case PW_YESEQ:
l = ":EQ";
break;
case PW_NO:
continue;
}
if(l)
{
if(!ctr)
notify(player,tprintf("%s powers:", poss(who)));
notify(player, tprintf("%s|+B|%s",
my_ljust(tprintf("|+W|[|+C|%s|+Y|%s|+W|]",
powers[k].name, l), MAX_POWERNAMELEN+3), powers[k].description));
ctr++;
}
}
if(ctr)
notify(player,
tprintf("\n|+C|%d |+W|/ |+C|%d |+B|powers", ctr, NUM_POWS));
else
notify(player, "|+W|No powers found.");
}
void do_powlist(OBJ *player)
{
int i;
for(i = 0;i < NUM_POWS;++i)
notify(player, tprintf("|+W|%c |+C|%s |+B|%s",
(get_pow(player, i) != PW_NO)?'*':' ',
my_ljust(powers[i].name, MAX_POWERNAMELEN), powers[i].description));
}