mux/src/powers.cpp File Reference

#include "copyright.h"
#include "autoconf.h"
#include "config.h"
#include "externs.h"
#include "command.h"
#include "powers.h"

Include dependency graph for powers.cpp:

Go to the source code of this file.

Functions

static bool ph_any (dbref target, dbref player, POWER power, int fpowers, bool reset)
static bool ph_god (dbref target, dbref player, POWER power, int fpowers, bool reset)
static bool ph_wiz (dbref target, dbref player, POWER power, int fpowers, bool reset)
void init_powertab (void)
void display_powertab (dbref player)
static POWERENTfind_power (dbref thing, char *powername)
bool decode_power (dbref player, char *powername, POWERSET *pset)
void power_set (dbref target, dbref player, char *power, int key)
bool has_power (dbref player, dbref it, char *powername)
char * powers_list (dbref player, dbref target)
void decompile_powers (dbref player, dbref thing, char *thingname)

Variables

static POWERENT gen_powers []


Function Documentation

bool decode_power ( dbref  player,
char *  powername,
POWERSET pset 
)

Definition at line 208 of file powers.cpp.

References hashfindLEN(), mudstate, notify, POWER_EXT, power_entry::powerpower, statedata::powers_htab, power_entry::powervalue, tprintf(), powerset::word1, and powerset::word2.

00209 {
00210     pset->word1 = 0;
00211     pset->word2 = 0;
00212 
00213     POWERENT *pent = (POWERENT *)hashfindLEN(powername, strlen(powername), &mudstate.powers_htab);
00214     if (!pent)
00215     {
00216         notify(player, tprintf("%s: Power not found.", powername));
00217         return false;
00218     }
00219     if (pent->powerpower & POWER_EXT)
00220     {
00221         pset->word2 = pent->powervalue;
00222     }
00223     else
00224     {
00225         pset->word1 = pent->powervalue;
00226     }
00227     return true;
00228 }

void decompile_powers ( dbref  player,
dbref  thing,
char *  thingname 
)

Definition at line 386 of file powers.cpp.

References CA_NO_DECOMP, gen_powers, power_entry::listperm, POWER_EXT, power_entry::powername, power_entry::powerpower, Powers, Powers2, and power_entry::powervalue.

00387 {
00388     POWERENT *fp;
00389 
00390     // Report generic powers.
00391     //
00392     POWER f1 = Powers(thing);
00393     POWER f2 = Powers2(thing);
00394 
00395     for (fp = gen_powers; fp->powername; fp++)
00396     {
00397         // Skip if we shouldn't decompile this power
00398         //
00399         if (fp->listperm & CA_NO_DECOMP)
00400         {
00401             continue;
00402         }
00403 
00404         // Skip if this power is not set.
00405         //
00406         if (fp->powerpower & POWER_EXT)
00407         {
00408             if (!(f2 & fp->powervalue))
00409             {
00410                 continue;
00411             }
00412         }
00413         else
00414         {
00415             if (!(f1 & fp->powervalue))
00416             {
00417                 continue;
00418             }
00419         }
00420 
00421         // Skip if we can't see this power.
00422         //
00423         if (!check_access(player, fp->listperm))
00424         {
00425             continue;
00426         }
00427 
00428         // We made it this far, report this power.
00429         //
00430         notify(player, tprintf("@power %s=%s", strip_ansi(thingname), fp->powername));
00431     }
00432 }

void display_powertab ( dbref  player  ) 

Definition at line 168 of file powers.cpp.

References alloc_lbuf, CA_GOD, CA_WIZARD, free_lbuf, gen_powers, God, power_entry::listperm, notify, power_entry::powername, safe_chr, safe_str, and Wizard.

Referenced by do_list().

00169 {
00170     char *buf, *bp;
00171     POWERENT *fp;
00172 
00173     bp = buf = alloc_lbuf("display_powertab");
00174     safe_str("Powers:", buf, &bp);
00175     for (fp = gen_powers; fp->powername; fp++)
00176     {
00177         if ((fp->listperm & CA_WIZARD) && !Wizard(player))
00178         {
00179             continue;
00180         }
00181         if ((fp->listperm & CA_GOD) && !God(player))
00182         {
00183             continue;
00184         }
00185         safe_chr(' ', buf, &bp);
00186         safe_str(fp->powername, buf, &bp);
00187     }
00188     *bp = '\0';
00189     notify(player, buf);
00190     free_lbuf(buf);
00191 }

static POWERENT* find_power ( dbref  thing,
char *  powername 
) [static]

Definition at line 193 of file powers.cpp.

References alloc_sbuf, free_sbuf, hashfindLEN(), mudstate, mux_strlwr(), statedata::powers_htab, SBUF_SIZE, and UNUSED_PARAMETER.

Referenced by has_power(), and power_set().

00194 {
00195     UNUSED_PARAMETER(thing);
00196 
00197     // Convert powername to canonical lowercase.
00198     //
00199     char *buff = alloc_sbuf("find_power");
00200     strncpy(buff, powername, SBUF_SIZE);
00201     buff[SBUF_SIZE-1] = '\0';
00202     mux_strlwr(buff);
00203     POWERENT *p = (POWERENT *)hashfindLEN(buff, strlen(buff), &mudstate.powers_htab);
00204     free_sbuf(buff);
00205     return p;
00206 }

bool has_power ( dbref  player,
dbref  it,
char *  powername 
)

Definition at line 293 of file powers.cpp.

References CA_GOD, CA_WIZARD, find_power(), God, power_entry::listperm, POWER_EXT, power_entry::powerpower, Powers, Powers2, power_entry::powervalue, and Wizard.

Referenced by FUNCTION().

00294 {
00295     POWERENT *fp = find_power(it, powername);
00296     if (!fp)
00297     {
00298         return false;
00299     }
00300 
00301     POWER fv;
00302     if (fp->powerpower & POWER_EXT)
00303     {
00304         fv = Powers2(it);
00305     }
00306     else
00307     {
00308         fv = Powers(it);
00309     }
00310 
00311     if (fv & fp->powervalue)
00312     {
00313         if ((fp->listperm & CA_WIZARD) && !Wizard(player))
00314         {
00315             return false;
00316         }
00317         if ((fp->listperm & CA_GOD) && !God(player))
00318         {
00319             return false;
00320         }
00321         return true;
00322     }
00323     return false;
00324 }

void init_powertab ( void   ) 

Definition at line 145 of file powers.cpp.

References alloc_sbuf, gen_powers, hashaddLEN(), hashfindLEN(), mudstate, mux_strlwr(), power_entry::powername, statedata::powers_htab, and SBUF_SIZE.

Referenced by main().

00146 {
00147     POWERENT *fp;
00148     char *nbuf = alloc_sbuf("init_powertab");
00149 
00150     for (fp = gen_powers; fp->powername; fp++)
00151     {
00152         strncpy(nbuf, fp->powername, SBUF_SIZE);
00153         nbuf[SBUF_SIZE-1] = '\0';
00154         mux_strlwr(nbuf);
00155 
00156         if (!hashfindLEN(nbuf, strlen(nbuf), &mudstate.powers_htab))
00157         {
00158             hashaddLEN(nbuf, strlen(nbuf), fp, &mudstate.powers_htab);
00159         }
00160     }
00161     free_sbuf(nbuf);
00162 }

static bool ph_any ( dbref  target,
dbref  player,
POWER  power,
int  fpowers,
bool  reset 
) [static]

Definition at line 18 of file powers.cpp.

References POWER_EXT, Powers, Powers2, s_Powers, s_Powers2, and UNUSED_PARAMETER.

Referenced by ph_god(), and ph_wiz().

00019 {
00020     UNUSED_PARAMETER(player);
00021 
00022     if (fpowers & POWER_EXT)
00023     {
00024         if (reset)
00025         {
00026             s_Powers2(target, Powers2(target) & ~power);
00027         }
00028         else
00029         {
00030             s_Powers2(target, Powers2(target) | power);
00031         }
00032     }
00033     else
00034     {
00035         if (reset)
00036         {
00037             s_Powers(target, Powers(target) & ~power);
00038         }
00039         else
00040         {
00041             s_Powers(target, Powers(target) | power);
00042         }
00043     }
00044     return true;
00045 }

static bool ph_god ( dbref  target,
dbref  player,
POWER  power,
int  fpowers,
bool  reset 
) [static]

Definition at line 51 of file powers.cpp.

References God, and ph_any().

00052 {
00053     if (!God(player))
00054     {
00055         return false;
00056     }
00057     return (ph_any(target, player, power, fpowers, reset));
00058 }

static bool ph_wiz ( dbref  target,
dbref  player,
POWER  power,
int  fpowers,
bool  reset 
) [static]

Definition at line 64 of file powers.cpp.

References ph_any(), and Wizard.

00065 {
00066     if (!Wizard(player))
00067     {
00068         return false;
00069     }
00070     return (ph_any(target, player, power, fpowers, reset));
00071 }

void power_set ( dbref  target,
dbref  player,
char *  power,
int  key 
)

Definition at line 234 of file powers.cpp.

References find_power(), power_entry::handler, mux_isspace, NOPERM_MESSAGE, notify, power_entry::powerpower, power_entry::powervalue, Quiet, and SET_QUIET.

Referenced by do_power().

00235 {
00236     // Trim spaces, and handle the negation character.
00237     //
00238     while (mux_isspace(*power))
00239     {
00240         power++;
00241     }
00242 
00243     bool negate = false;
00244     if (*power == '!')
00245     {
00246         negate = true;
00247         power++;
00248     }
00249     while (mux_isspace(*power))
00250     {
00251         power++;
00252     }
00253 
00254     // Make sure a power name was specified.
00255     //
00256     if (*power == '\0')
00257     {
00258         if (negate)
00259         {
00260             notify(player, "You must specify a power to clear.");
00261         }
00262         else
00263         {
00264             notify(player, "You must specify a power to set.");
00265         }
00266         return;
00267     }
00268     POWERENT *fp = find_power(target, power);
00269     if (fp == NULL)
00270     {
00271         notify(player, "I don't understand that power.");
00272         return;
00273     }
00274 
00275     // Invoke the power handler, and print feedback.
00276     //
00277     bool result = fp->handler(target, player, fp->powervalue,
00278                  fp->powerpower, negate);
00279     if (!result)
00280     {
00281         notify(player, NOPERM_MESSAGE);
00282     }
00283     else if (!(key & SET_QUIET) && !Quiet(player))
00284     {
00285         notify(player, (negate ? "Cleared." : "Set."));
00286     }
00287 }

char* powers_list ( dbref  player,
dbref  target 
)

Definition at line 330 of file powers.cpp.

References alloc_lbuf, CA_GOD, CA_WIZARD, gen_powers, God, power_entry::listperm, POWER_EXT, power_entry::powername, power_entry::powerpower, Powers, Powers2, power_entry::powervalue, safe_chr, safe_str, and Wizard.

Referenced by debug_examine(), do_examine(), and FUNCTION().

00331 {
00332     // Allocate the return buffer.
00333     //
00334     char *buff = alloc_lbuf("powers_list");
00335     char *bp = buff;
00336 
00337     bool bFirst = true;
00338     POWERENT *fp;
00339     for (fp = gen_powers; fp->powername; fp++)
00340     {
00341         POWER fv;
00342         if (fp->powerpower & POWER_EXT)
00343         {
00344             fv = Powers2(target);
00345         }
00346         else
00347         {
00348             fv = Powers(target);
00349         }
00350 
00351         if (fv & fp->powervalue)
00352         {
00353             if (  (fp->listperm & CA_WIZARD)
00354                && !Wizard(player))
00355             {
00356                 continue;
00357             }
00358             if (  (fp->listperm & CA_GOD)
00359                && !God(player))
00360             {
00361                 continue;
00362             }
00363             if (bFirst)
00364             {
00365                 bFirst = false;
00366             }
00367             else
00368             {
00369                 safe_chr(' ', buff, &bp);
00370             }
00371             safe_str(fp->powername, buff, &bp);
00372         }
00373     }
00374 
00375     // Terminate the string, and return the buffer to the caller.
00376     //
00377     *bp = '\0';
00378     return buff;
00379 }


Variable Documentation

POWERENT gen_powers[] [static]

Definition at line 102 of file powers.cpp.

Referenced by decompile_powers(), display_powertab(), init_powertab(), and powers_list().


Generated on Mon May 28 04:40:21 2007 for MUX by  doxygen 1.4.7