|
Meterbar for attributes (Another) [by Professor Hoopster] |
|
|
|
Posted Wednesday, August 12th @ 11:31:20 PM, by George Greer in the Utils dept.
Added Dec 3, 1996. Click the link below to read it or download it.
From: Professor Hoopster <hoopy@notfoo.res.cmu.edu>
Subject: Bar chart code
Some people have been discussing how to make a bar graph of point scales
rather than just straight numbers...thought you might be interested in
how I did it for my MUD, and how I incorporated it into my score command.
(BTW, the PLR_IMMORT and quickening stuff is for the immortality (aka
remort) system in the mud, so if you don't have it (or have something
else), you'll probably want to change those parts.)
Most of the point values in my mud are changed to longs, so if you still
use smaller storage elements you might want to change the %ld fields to
%d. Anyway, I'm just including the relevent part here. You also need to
add a command 'scorebar' as a do_gen_tog, and add SCMD_SCOREBAR and a
field to the messages section of do_gen_tog. And a PRF_ flag. I think
that's about it.
/* Note, make_bar dirties buf2 */
char *make_bar(long val, long max, long len)
{
unsigned int i, n;
char *pos = buf2;
strcpy(pos++, "[");
if (val > max)
{
for (i = 0; i < len; i++)
*(pos++) = '*';
strcpy(pos, "]+");
} else {
for (i = (val * len) / max, n = 0; n < i; n++)
*(pos++) = '*';
while ((n++)<len)
*(pos++) = ' ';
strcpy(pos, "]");
}
return buf2;
}
ACMD(do_score)
{
struct time_info_data playing_time;
struct time_info_data real_time_passed(time_t t2, time_t t1);
sprintf(buf, "You are %s %s (level %ld)%s.\r\n",
GET_NAME(ch), GET_TITLE(ch), GET_LEVEL(ch),
PLR_FLAGGED(ch, PLR_IMM)?" (Immortal)":"");
if (PRF_FLAGGED(ch, PRF_SCOREBAR))
{
static char bufs[4][128];
static char bufs2[4][128];
static char bufs3[4][128];
int l, i;
sprintf(bufs[0], "[%ld/%ld]", GET_HIT(ch),GET_MAX_HIT(ch));
sprintf(bufs[1], "[%ld/%ld]", GET_MANA(ch), GET_MAX_MANA(ch));
sprintf(bufs[2], "[%ld/%ld]", GET_MOVE(ch), GET_MAX_MOVE(ch));
sprintf(bufs[3], "[%ld/%ld]", GET_QUICK(ch), GET_MAX_QUICK(ch));
l = MAX(MAX(strlen(bufs[0]),strlen(bufs[1])),MAX(strlen(bufs[2]),
strlen(bufs[3])));
sprintf(bufs2[0], " Hit: %%%ds ", l);
sprintf(bufs2[1], " Mana: %%%ds ", l);
sprintf(bufs2[2], "Moves: %%%ds ", l);
sprintf(bufs2[3], "Quick: %%%ds ", l);
for (i = 0; i < 4; i++)
sprintf(bufs3[i], bufs2[i], bufs[i]);
sprintf(buf, "%s%s%s\r\n", buf, bufs3[0],
make_bar(GET_HIT(ch), GET_MAX_HIT(ch), 50));
sprintf(buf, "%s%s%s\r\n", buf, bufs3[1],
make_bar(GET_MANA(ch), GET_MAX_MANA(ch), 50));
sprintf(buf, "%s%s%s\r\n", buf, bufs3[2],
make_bar(GET_MOVE(ch), GET_MAX_MOVE(ch), 50));
if (PLR_FLAGGED(ch, PLR_IMM))
sprintf(buf, "%s%s%s\r\n", buf, bufs3[3],
make_bar(GET_QUICK(ch), GET_MAX_QUICK(ch), 50));
} else {
*buf2 = 0;
if (PLR_FLAGGED(ch, PLR_IMM))
sprintf(buf2, " Quickening: [%ld/%ld]", GET_QUICK(ch),
GET_MAX_QUICK(ch));
sprintf(buf, "%sHit: [%ld/%ld] Mana: [%ld/%ld] Move: [%ld/%ld]%s\r\n",
buf, GET_HIT(ch), GET_MAX_HIT(ch), GET_MANA(ch), GET_MAX_MANA(ch),
GET_MOVE(ch), GET_MAX_MOVE(ch), buf2);
}
--- the rest of your score report goes here
<< Meterbar for Attributes [by Adam Days] | Reply | View as text | Threaded | Mob Flag Fast Aggression [by Lars Juul] >> |
|
Related Links |
|
|
|
CircleMUD Snippets |
|
|
Note: Not all of these snippets will work perfectly with
your version of code, so be prepared to fix one
or two bugs that may arise, and please let me know
what you needed to do to fix it. Sending a corrected
version is always welcome.
|
Finally, if you wish to use any of the snippets from this
page, you are more than welcome, just mention the
authors in your credits. If you wish to release any
of these snippets to the public on another site,
contact me FIRST.
|
|
|
|
|
|
|