#include <mudlib.h>
#include <i_to_str.h>
#define AMT_MONEY (int)this_object()->query_money()
#define NAME (string)this_object()->query_name()
#define LEVEL (int)this_player()->query_level()
/**************************************************************************/
/* put */
status put(string item)
{
object *items;
string container;
int size, i, wt;
object ob, to;
string item_name;
int abort;
status havePut;
if(this_object()->query_ghost())
{
tell_object(this_object(),"It passes straight through your hands...\n");
return 1;
}
if((int)this_object()->query_real_light() < 1)
{
tell_object(this_object(), "It's too dark to do that.\n");
return 1;
}
if(!item)
{
tell_object(this_object(),"Usage: put <item> in <container>\n");
return 1;
}
sscanf(item, "%s in %s", item, container);
sscanf(item, "%s on %s", item, container);
if(!container)
{
tell_object(this_object(),"Usage: put <item> in <container>\n");
return 1;
}
container = lower_case(container);
if(!(to = present(container, this_object())))
{
if(!(to = present(container, environment())))
{
tell_object(this_object(),"There are no " + container + "s here!\n");
return 1;
}
if(living(to))
{
tell_object(this_object(),"You cannot do that!\n");
return 1;
}
}
if(item == "all")
{
items = all_inventory();
}
else if(!(ob = present(item, this_object())))
{
if (!(ob = present (item, environment())))
{
tell_object(this_object(),"You do not have "+ item +".\n");
return 1;
}
}
if(ob) items = ({ ob, });
for(i = 0, size = sizeof(items); i < size; i++)
{
if(items[i] == to) continue; /* can't move items into self */
if(!objectp(items[i]) || living(items[i])) continue; /* no move living */
if(!(item_name = (string)items[i]->short())) continue; /* no move invis*/
if(++abort > 30)
{
tell_object(this_object(), "You only pick up "+int_to_str(30)+
" "+items[i]->query_short()+"\n");
return 1;
}
item = (string)items[i]->query_name();
if (item)
item_name = item;
if ((this_object() == environment(items[i]) && items[i]->drop())
|| (this_object() != environment(items[i]) && !items[i]->get()))
{
write ("You cannot put the "+ item_name +" in "+ container +".\n");
continue;
}
if(!to->can_put_and_get(0))
{
tell_object(this_object(),"You cannot do that!\n");
return 1;
}
wt = (int)items[i]->query_weight();
if (!to->add_weight(wt))
{
write ("The "+ container +" cannot hold the "+ item_name +".\n");
say (NAME+" attempts to put the "+item_name+" in the "+container+".\n");
continue;
}
environment(items[i])->add_weight(-wt);
#ifdef NATIVE_MODE
items[i]->move(to);
#else
move_object(items[i], to);
#endif /* NATIVE_MODE */
write("You put the "+ item_name +" into the "+ container +".\n");
say(NAME+" puts the "+ item_name +" into the "+ container + ".\n");
havePut = 1;
}
if (!havePut)
{
tell_object(this_object(),"Put? You move the air about in the "+
container +".\n");
}
return 1;
}
/***************************************************************************/
/* get */
status pick_up(string item)
{
string container;
object from;
object *items, ob;
int abort, haveGet;
string item_name;
int size, i, wt;
if(this_object()->query_ghost())
{
tell_object(this_object(),"It passes straight through your hands...\n");
return 1;
}
if((int)this_object()->query_real_light() < 1)
{
tell_object(this_object(), "It's too dark to do that.\n");
return 1;
}
if(!item)
{
tell_object(this_object(),"Usage: get <item|all>\n"+
" get <item|all> from <container>\n");
return 1;
}
sscanf(item, "%s from %s", item, container);
if(container)
{
container = lower_case(container);
if(!(from = present(container, this_object()))) {
if(!(from = present(container, environment()))) {
if(!environment()->id(container))
{
write("There is no " + container + " here.\n");
}
else
{
tell_object(this_object(),"You cannot get anything from the "+
container +".\n");
}
return 1;
}
}
if(living(from))
{
tell_object(this_object(),"You cannot do that!\n");
return 1;
}
}
else
{
from = environment();
}
if(item == "all")
{
items = all_inventory(from);
}
else if(!(ob = present(item, from)))
{
if(!environment()->id(item))
{
tell_object(this_object(),"There is no "+ item +" in the "+
((container) ? container : "room") +".\n");
}
else
{
tell_object(this_object(),"You cannot get the "+ item +".\n");
}
return 1;
}
if(ob) items = ({ ob, });
for(i = 0, size = sizeof(items); i < size; i++)
{
if(items[i] == this_object()) continue; /* can't move items into self */
if(!items[i]->get()) continue; /* can't pick it up */
if(!objectp(items[i]) || living(items[i])) continue; /* no move living */
if(!(item_name = (string)items[i]->short())) continue; /* no move invis*/
if(++abort > 30)
{
tell_object(this_object(), "You get only "+int_to_str(30)+
" "+items[i]->query_short()+"\n");
return 1;
}
item = (string)items[i]->query_name();
if (item)
item_name = item;
/*
if((environment() != environment(items[i])) || (!items[i]->get()))
{
write ("You cannot get the "+ item_name +".\n");
continue;
}
*/
if (!from->can_put_and_get(0))
{
tell_object(this_object(),"You cannot do that!\n");
return 1;
}
wt = (int)items[i]->query_weight();
if (!this_object()->add_weight(wt))
{
write ("You're not strong enough to carry the "+ item_name +".\n");
say (NAME+" attempts to carry the "+item_name+".\n");
continue;
}
environment(items[i])->add_weight(-wt);
#ifdef NATIVE_MODE
items[i]->move(this_object());
#else
move_object(items[i], this_object());
#endif /* NATIVE_MODE */
write("You get the "+ item_name +".\n");
say(NAME+" gets the "+ item_name +".\n");
haveGet = 1;
}
if (!haveGet)
{
tell_object(this_object(),"Get? You move the air about.\n");
}
return 1;
}
/***************************************************************************/
/* give */
status give_object(string item)
{
string who;
object *items;
object ob, dest_ob;
int amt;
int size, i, wt;
string item_name;
int abort;
int haveGive;
string coins_type;
if(this_object()->query_ghost())
{
write("It passes straight through your hands...\n");
return 1;
}
if((int)this_object()->query_real_light() < 1)
{
tell_object(this_object(), "It's too dark to do that.\n");
return 1;
}
if(!item)
{
write("Usage: give <item|all> to <who>\n"+
" give <amount> coins to <who>\n");
return 1;
}
sscanf(item, "%s to %s", item, who);
sscanf(item, "%d %s coins to %s", amt, coins_type, who);
sscanf(item, "%d coins to %s", amt, who);
sscanf(item, "%d coin to %s", amt, who);
if(!who) return give_object(0);
if(!(dest_ob = present(who, environment())))
{
write(capitalize(who)+" is not here.\n");
return 1;
}
if(!living(dest_ob))
{
write("Thats not giving it away, its throwing it away.\n");
return 1;
}
if(amt)
{
if(amt < 1)
{
write("Are you looking for a loan?\n");
return 1;
}
if(LEVEL < 2)
{
write("Your level is not high enough to be a money lender.\n");
return 1;
}
if(coins_type == "platinum") amt *= PLATINUM;
else
if(coins_type == "gold") amt *= GOLD;
else
if(coins_type == "silver") amt *= SILVER;
else
amt *= COPPER;
if(amt > AMT_MONEY) amt = AMT_MONEY;
this_object()->add_money(-amt);
this_object()->save_me(1);
dest_ob->add_money(amt);
dest_ob->save_character();
tell_object(this_object(),"You give "+capitalize(who)+" "+amt+
" coin"+((amt == 1) ? "" : "s")+".\n");
say(NAME+" gives "+capitalize(who)+" "+amt+
" coin"+((amt == 1) ? "" : "s")+".\n", dest_ob);
tell_object(dest_ob,NAME+" gives you "+amt+
" coin"+((amt == 1) ? "" : "s")+".\n");
return 1;
}
if(item == "all") {
items = all_inventory();
}
else if(!(ob = present(item, this_object())))
{
if(!(ob = present(item, environment())))
{
tell_object(this_object(),"You do not have "+ item +".\n");
return 1;
}
}
if(ob) items = ({ ob, });
for(i = 0, size = sizeof(items); i < size; i++)
{
if(items[i] == dest_ob) continue; /* can't move items into self */
if(!objectp(items[i]) || living(items[i])) continue; /* no move living */
if(!(item_name = (string)items[i]->short())) continue; /* no move invis*/
if(++abort > 30)
{
tell_object(this_object(), "You give only "+int_to_str(30)+
" "+items[i]->query_short()+"\n");
return 1;
}
item = (string)items[i]->query_name();
if (item)
item_name = item;
if ((this_object() == environment(items[i]) && items[i]->drop())
|| (this_object() != environment(items[i]) && !items[i]->get()))
{
write ("You cannot give away the "+ item_name +".\n");
continue;
}
wt = (int)items[i]->query_weight();
if (!dest_ob->add_weight(wt))
{
write (dest_ob->query_name()+" cannot carry the "+ item_name +".\n");
say (NAME+" attempts give "+ item_name +" to "+
dest_ob->query_name()+".\n",dest_ob);
tell_object (dest_ob,NAME+" trys to give you the "+ item_name
+" but you cannot carry it.\n");
continue;
}
environment(items[i])->add_weight(-wt);
#ifdef NATIVE_MODE
items[i]->move(dest_ob);
#else
move_object(items[i], dest_ob);
#endif /* NATIVE_MODE */
write("You give the "+ item_name +" to "+ dest_ob->query_name() +".\n");
say(NAME+" gives the "+ item_name +" to "+ dest_ob->query_name()
+".\n",dest_ob);
tell_object(dest_ob,NAME +" gives you the "+ item_name +".\n");
haveGive = 1;
}
if (!haveGive)
{
tell_object(this_object(),"Give? You move the air about.\n");
}
return 1;
}
/***********************************************************************/
/* drop */
status drop_thing(string item)
{
string container;
int size, i, wt;
object ob, to;
object *items;
int amt;
string item_name;
string coins_type;
int abort;
status haveDrop;
if(!item)
{
write("Usage: drop <item|all>\n"+
" drop <item|all> in <container>\n"+
" drop <amount> coins\n");
return 1;
}
sscanf(item, "%d %s coins", amt, coins_type);
sscanf(item, "%d coins", amt);
sscanf(item, "%d coin", amt);
sscanf(item, "%s in %s", item, container);
if(amt)
{
if(amt < 1)
{
write("Are you looking for a loan?\n");
return 1;
}
if(LEVEL < 2)
{
write("Something prevents you.\n");
return 1;
}
if(coins_type == "platinum") amt *= PLATINUM;
else if(coins_type == "gold") amt *= GOLD;
else if(coins_type == "silver") amt *= SILVER;
else amt *= COPPER;
if(amt > AMT_MONEY) amt = AMT_MONEY;
this_object()->add_money(-amt);
this_object()->save_me(1);
ob = clone_object(MONEY);
ob->set_money(amt);
#ifdef NATIVE_MODE
ob->move(environment());
#else
move_object(ob, environment());
#endif /* NATIVE_MODE */
write("You drop "+amt+" coin"+((amt == 1) ? "" : "s")+".\n");
say(NAME+" drops "+amt+" coin"+((amt == 1) ? "" : "s")+".\n");
return 1;
}
if(container)
{
container = lower_case(container);
if(!(to = present(container, this_object())))
{
if(!(to = present(container, environment())))
{
write("There is no " + container + " here.\n");
return 1;
}
}
if(living(to))
{
write("You can't do that!\n");
return 1;
}
}
else
{
to = environment();
}
if(item == "all") {
items = all_inventory();
}
else if(!(ob = present(item, this_object())))
{
tell_object(this_object(),"You don't have the "+ item +".\n");
return 1;
}
if(ob) items = ({ ob, });
for(i = 0, size = sizeof(items); i < size; i++)
{
if(!objectp(items[i]) || living(items[i])) continue; /* no move living */
if(!(item_name = (string)items[i]->short())) continue; /* no move invis*/
if(++abort > 30)
{
tell_object(this_object(), "You drop only "+int_to_str(30)+
" "+items[i]->query_short()+"\n");
return 1;
}
item = (string)items[i]->query_name();
if (item)
item_name = item;
if ((this_object() == environment(items[i]) && items[i]->drop())
|| (this_object() != environment(items[i]) && !items[i]->get()))
{
write ("You cannot drop the "+ item_name +".\n");
continue;
}
wt = (int)items[i]->query_weight();
if (to != environment())
{
if (!to->can_put_and_get(0))
{
tell_object(this_object(),"You cannot do that!\n");
return 1;
}
if (!to->add_weight(wt))
{
write ("You cannot drop the "+ item_name +".\n");
say (NAME+" attempts drop the "+ item_name +".\n");
continue;
}
}
this_object()->add_weight(-wt);
#ifdef NATIVE_MODE
items[i]->move(to);
#else
move_object(items[i], to);
#endif /* NATIVE_MODE */
write("You drop the "+ item_name +".\n");
say(NAME+" drops the "+ item_name +".\n");
haveDrop = 1;
}
if (!haveDrop)
{
tell_object(this_object(),"Drop? You fidget in your pockets.\n");
}
return 1;
}