give.c
TinyMAZE/src/comm/give.c · 4.5 KB
From the archive TinyMAZEv2.5a.tar.gz
Download the archive « Back to the archive contents
#include <stdio.h>
#include <ctype.h>
#include "db.h"
#include "externs.h"
void do_giveto(OBJ *player, char *arg, char *amnt)
{
int amount;
OBJ *who;
char buf[4096];
who = match_object(player, arg, TYPE_PLAYER);
if(!who)
{
notify(player, no_match(arg));
return;
}
amount = atoi(amnt);
if(!amount)
{
notify(player, tprintf("What good would giving 0 %s do?",
config.currency_plural));
return;
}
if(amount < 0 && !controls(player, who, POW_STEAL))
{
notify(player, "You can only @giveto positive amounts.");
return;
}
if(!payfor(player, amount))
{
notify(player, "You can't pay for that much!");
return;
}
giveto(who, amount);
notify(player, "Given.");
strcpy(buf, unparse_object(who, who));
log_misc(tprintf("%s gave %s %d %s",
unparse_object(player, player), buf, amount,
check_plural(amount, config.currency_name, config.currency_plural)));
}
void do_give(OBJ *player, char *recipient, char *amnt)
{
OBJ *who, *thing;
int amount;
char *s;
char buf[4096], buf2[4096];
who = match_object(player, recipient, TYPE_PLAYER);
if(!who)
{
notify(player, no_match(recipient));
return;
}
/* See if amount is all digits */
s = amnt;
if(*s == '-')
s++;
while(isdigit(*s))
s++;
if(*s) /* Must be giving an object */
{
thing = match_object(player, amnt, TYPE_THING);
if(!thing)
{
notify(player, "You're carrying no such item!");
return;
}
if(!could_doit(player, thing, "LOCK"))
if(!controls(player, who, POW_TELEPORT))
{
notify(player, perm_denied());
return;
}
moveto(thing, who);
notify(who,
tprintf("%s gave you %s.", name(player), name(thing)));
notify(player, "Given.");
notify(thing, tprintf("%s gave you to %s.", name(player), name(who)));
strcpy(buf, unparse_object(who, who));
strcpy(buf2, unparse_object(thing, thing));
log_misc(tprintf("%s gave %s %s",
unparse_object(player, player), buf, buf2));
return;
}
amount = atoi(amnt);
if(!amount)
{
notify(player, tprintf("Why give 0 %s?", config.currency_plural));
return;
}
if(amount < 0 && !controls(player, who, POW_STEAL))
{
notify(player, tprintf("You must specify a positive number of %s.",
config.currency_plural));
return;
}
/* Try to do the give */
if(!payfor(player, amount))
{
notify(player, tprintf("You don't have that many %s to give!",
config.currency_plural));
return;
}
if(amount < 0)
notify(player, tprintf("You take %d %s from %s.", -(amount),
check_plural(-(amount), config.currency_name, config.currency_plural),
name(who)));
else
notify(player, tprintf("You give %d %s to %s.", amount,
check_plural(amount, config.currency_name, config.currency_plural),
name(who)));
if(amount < 0)
notify(who, tprintf("%s takes %d %s from you.", name(player), -(amount),
check_plural(-(amount), config.currency_name, config.currency_plural)));
else
notify(who, tprintf("%s gives you %d %s%s.",
name(player), amount,
check_plural(amount, config.currency_name, config.currency_plural)));
giveto(who, amount);
strcpy(buf, unparse_object(who, who));
log_misc(tprintf("%s gave %s %d %s",
unparse_object(player, player), buf, amount,
check_plural(amount, config.currency_name, config.currency_plural)));
}
void do_money(OBJ *player, char *arg)
{
OBJ *who;
int total = 0;
char *str;
char buf[1024];
if(!*arg)
who = player;
else
{
who = match_object(player, arg, TYPE_PLAYER);
if(!who)
{
notify(player, no_match(arg));
return;
}
if(!controls(player, who, POW_EXAMINE) && !(who->flags & VISIBLE))
{
notify(player, perm_denied());
return;
}
}
/* Calculate money */
total = Pennies(who);
if(inf_mon(who))
str = "|+G|(INFINITE)";
else
str = "";
notify(player, tprintf("|+B|.%s.", my_string("-", 46)));
notify(player, tprintf("|+B|||+W|%s|+B||",
my_center("FUNDS", 46)));
notify(player, tprintf("|+B||%s|", my_string("-", 46)));
strcpy(buf, comma(tprintf("%ld", Pennies(who))));
notify(player, tprintf("|+B|| %s|+B||",
my_ljust(tprintf("|+C|On Hand|+W| : |+Y|%s %s",
buf, str), 45)));
strcpy(buf, comma(tprintf("%d", total)));
notify(player, tprintf("|+B|| %s|+B||",
my_ljust(tprintf("|+C|Total Funds |+W|: |+Y|%s",
buf), 45)));
notify(player, tprintf("|+B|`%s'", my_string("-", 46)));
}