dsII/extra/wolfpaw/
dsII/lib/cmds/admins/
dsII/lib/cmds/common/
dsII/lib/cmds/creators/include/
dsII/lib/cmds/creators/include/SCCS/
dsII/lib/daemon/services/
dsII/lib/doc/
dsII/lib/domains/Ylsrim/
dsII/lib/domains/Ylsrim/adm/
dsII/lib/domains/Ylsrim/armor/
dsII/lib/domains/Ylsrim/broken/
dsII/lib/domains/Ylsrim/fish/
dsII/lib/domains/Ylsrim/meal/
dsII/lib/domains/Ylsrim/npc/
dsII/lib/domains/Ylsrim/virtual/
dsII/lib/domains/Ylsrim/weapon/
dsII/lib/domains/campus/adm/
dsII/lib/domains/campus/etc/
dsII/lib/domains/campus/meals/
dsII/lib/domains/campus/npc/
dsII/lib/domains/campus/txt/
dsII/lib/domains/campus/txt/ai/charles/
dsII/lib/domains/campus/txt/ai/charles/bak2/
dsII/lib/domains/campus/txt/ai/charles/bak2/bak1/
dsII/lib/domains/campus/txt/ai/charly/
dsII/lib/domains/campus/txt/ai/charly/bak/
dsII/lib/domains/campus/txt/jenny/
dsII/lib/domains/default/creator/
dsII/lib/domains/default/doors/
dsII/lib/domains/default/etc/
dsII/lib/domains/default/weap/
dsII/lib/domains/town/doors/
dsII/lib/domains/town/txt/
dsII/lib/domains/town/virtual/
dsII/lib/lib/comp/
dsII/lib/lib/lvs/
dsII/lib/lib/user/
dsII/lib/lib/virtual/
dsII/lib/log/archive/
dsII/lib/log/chan/
dsII/lib/log/errors/
dsII/lib/log/open/
dsII/lib/obj/book_source/
dsII/lib/obj/include/
dsII/lib/realms/template/
dsII/lib/realms/template/area/armor/
dsII/lib/realms/template/area/npc/
dsII/lib/realms/template/area/obj/
dsII/lib/realms/template/area/room/
dsII/lib/realms/template/area/weap/
dsII/lib/realms/template/bak/
dsII/lib/realms/template/cmds/
dsII/lib/save/
dsII/lib/save/kills/o/
dsII/lib/secure/cfg/
dsII/lib/secure/cfg/classes/
dsII/lib/secure/cfg/races/SCCS/
dsII/lib/secure/cmds/creators/include/
dsII/lib/secure/cmds/players/
dsII/lib/secure/cmds/players/include/
dsII/lib/secure/daemon/include/
dsII/lib/secure/lib/
dsII/lib/secure/lib/include/
dsII/lib/secure/lib/net/
dsII/lib/secure/lib/net/include/
dsII/lib/secure/lib/std/
dsII/lib/secure/modules/
dsII/lib/secure/npc/
dsII/lib/secure/obj/include/
dsII/lib/secure/room/
dsII/lib/secure/save/boards/
dsII/lib/secure/save/postal/c/cratylus/
dsII/lib/secure/save/votes/
dsII/lib/secure/tmp/
dsII/lib/secure/verbs/creators/
dsII/lib/shadows/
dsII/lib/spells/
dsII/lib/tmp/
dsII/lib/verbs/admins/include/
dsII/lib/verbs/common/
dsII/lib/verbs/common/include/
dsII/lib/verbs/creators/include/
dsII/lib/verbs/players/include/SCCS/
dsII/lib/verbs/rooms/
dsII/lib/verbs/rooms/include/
dsII/lib/www/
dsII/v22.2b14/
dsII/v22.2b14/Win32/
dsII/v22.2b14/compat/
dsII/v22.2b14/compat/simuls/
dsII/v22.2b14/testsuite/
dsII/v22.2b14/testsuite/clone/
dsII/v22.2b14/testsuite/command/
dsII/v22.2b14/testsuite/data/
dsII/v22.2b14/testsuite/etc/
dsII/v22.2b14/testsuite/include/
dsII/v22.2b14/testsuite/inherit/
dsII/v22.2b14/testsuite/inherit/master/
dsII/v22.2b14/testsuite/log/
dsII/v22.2b14/testsuite/single/
dsII/v22.2b14/testsuite/single/tests/compiler/
dsII/v22.2b14/testsuite/single/tests/efuns/
dsII/v22.2b14/testsuite/single/tests/operators/
dsII/v22.2b14/testsuite/u/
dsII/v22.2b14/tmp/
dsII/win32/
/*    /lib/meal.c
 *    from the Dead Souls LPC Library
 *    standard food and drink code
 *    created by descartes of Borg 950603
 *    Version: @(#) meal.c 1.3@(#)
 *    Last modified: 97/01/03
 */

#include <lib.h>
#include <function.h>
#include <meal_types.h>
#include <rounds.h>
#include <vendor_types.h>
#include "include/meal.h"

inherit LIB_BAIT_WITH;
inherit LIB_ITEM;

private int MealStrength, MealType;
private string EmptyItem, EmptyName, OtherMessage;
private mixed EmptyShort, EmptyLong, MyMessage;

static void create() {
    item::create();
    MealType = MEAL_ALCOHOL;
    EmptyItem = 0;
    EmptyName = "bottle";
    EmptyShort = "an empty bottle";
    EmptyLong = "This empty bottle once contained some alcohol.";
    MyMessage = "You drink your drink.";
    OtherMessage = "$N drinks $P drink.";
    SetVendorType(VT_DRINK);
    AddSave( ({ "MealStrength", "MealType", "BaitStrength" }) );
}

mixed direct_drink_obj() { 
    if( environment() != this_player() ) return "#You don't have that!";
    if( MealType & MEAL_FOOD ) return "Wouldn't you rather eat it?";
    return (int)this_player()->CanDrink(this_object());
}

mixed direct_drink_from_obj() {
    if( MealType & MEAL_FOOD ) return 0;
    if( environment() != this_player() ) return "#You don't have that!";
    return (int)this_player()->CanDrink(this_object());
}

mixed direct_eat_obj() {
    if( environment() != this_player() ) return "#You don't have that!";
    if( !(MealType & MEAL_FOOD) ) return "Wouldn't you rather drink it?";
    return (int)this_player()->CanEat(this_object());
}

static mixed AddSave(mixed *vars) { return item::AddSave(vars); }

string GetShort() { return item::GetShort(); }

int eventDestruct() { return item::eventDestruct(); }

mixed eventDrink(object who) {
    mixed tmp;
    int x;
    object ob;

    if( (tmp = (mixed)who->eventDrink(this_object())) != 1 ) return tmp;
    if( (x = functionp(MyMessage)) && !(x & FP_OWNER_DESTED) ) {
	evaluate(MyMessage, who);
    }
    else {
	string mymsg, othermsg;

	mymsg = replace_string(MyMessage, "$P", "your");
	othermsg = replace_string(OtherMessage, "$P", possessive(who));
	mymsg = replace_string(mymsg, "$N", "you");
	othermsg = replace_string(othermsg, "$N", (string)who->GetName());
	who->eventPrint( capitalize(mymsg) );
	environment(who)->eventPrint( capitalize(othermsg), who );
    }

    ob = new(GetEmptyItem() || LIB_ITEM);
    if( base_name(ob) == LIB_ITEM ) {
	ob->SetKeyName(GetEmptyName());
	ob->SetId( ({ GetEmptyName(), "container", "empty container" }) );
	ob->SetShort(GetEmptyShort());
	ob->SetLong(GetEmptyLong());
	ob->SetBaseCost(1);
	ob->SetMass(10);
	ob->SetDestroyOnSell();
    }
    if( !((int)ob->eventMove(who)) ) {
	who->eventPrint("You drop " + (string)ob->GetShort() + ".");
	environment(who)->eventPrint((string)who->GetName() +
	  " drops " + (string)ob->GetShort() + ".", who);
	ob->eventMove(environment(who));
    }

    if( x = GetPoison() ) {
	if( random((int)who->GetStatLevel("luck")) > 35 )
	    who->eventPrint("That didn't seem to taste quite right.");
	who->AddPoison(x);
    }
    Destruct();
    return 1;
}

mixed eventEat(object who) {
    mixed tmp;
    int x;

    if( (tmp = (mixed)who->eventEat(this_object())) != 1 ) return tmp;
    if( (x = functionp(MyMessage)) && !(x & FP_OWNER_DESTED) ) {
	evaluate(MyMessage, who);
    }
    else {
	string mymsg, othermsg;

	mymsg = replace_string(MyMessage, "$P", "your");
	othermsg = replace_string(OtherMessage, "$P",
	  possessive(who));
	mymsg = replace_string(mymsg, "$N", "you");
	othermsg = replace_string(othermsg, "$N", (string)who->GetName());
	who->eventPrint( capitalize(mymsg) );
	environment(who)->eventPrint( capitalize(othermsg), who );
    }
    if( x = GetPoison() ) {
	if( random((int)who->GetStatLevel("luck")) > 35 )
	    who->eventPrint("You notice a strange aftertaste.");
	who->AddPoison(x);
    }
    Destruct();
    return 1;
}

int eventPoison(object who, object agent, int x) {
    who->eventPrint("You put some poison "
      "in " + add_article(GetShort()) + ".");
    environment(who)->eventPrint( (string)who->GetName()+" puts something "
      "in " + add_article(GetShort()) + ".", who);
    AddPoison(x);
    return 1;
}

string SetEmptyItem(string file) { return (EmptyItem = file); }

string GetEmptyItem() { return EmptyItem; }

string SetEmptyName(string str) { return (EmptyName = str); }

string GetEmptyName() { return EmptyName; }

mixed SetEmptyShort(mixed val) { return (EmptyShort = val); }

mixed GetEmptyShort() { return EmptyShort; }

mixed SetEmptyLong(mixed val) { return (EmptyLong = val); }

mixed GetEmptyLong() { return EmptyLong; }

int SetMealType(int x) {
    int vt = 0;

    if( x & MEAL_FOOD ) {
	vt |= VT_FOOD;
	MyMessage = "You eat your food.";
	OtherMessage = "$N eats $P food.";
    }
    if( x & MEAL_DRINK ) vt |= VT_DRINK;
    SetVendorType(vt);
    return (MealType = x);
}

int GetMealType() { return MealType; }

int SetStrength(int x) { return (MealStrength = x); }

int GetStrength() { return MealStrength; }

varargs void SetMealMessages(mixed array val...) {
    if( !arrayp(val) ) {
	error(sprintf("Bad argument 1 to SetMealMessages(): %O\n", val));
    }
    if( sizeof(val) == 1 ) {
	if( arrayp(val[0]) ) SetMealMessages(val[0]...);
	else if( stringp(val[0]) || functionp(val[0]) ) MyMessage = val[0];
	else error(sprintf("Bad argument 1 to SetMealMessages(): %O\n",
		val[0]));
	return;
    }
    if( !stringp(val[0]) )
	error(sprintf("Bad argument 1 to SetMealMessages(): %O\n", val[0]));
    else if( !stringp(val[1]) ) 
	error(sprintf("Bad argument 2 to SetMealMessages(): %O\n", val[1]));
    MyMessage = val[0];
    OtherMessage = val[1];
}

mixed *GetMealMessages() { return ({ MyMessage, OtherMessage }); }

int GetValue() {
    int x;

    x = GetStrength();
    return (x * (6 + x)) / 10 + 10;
}