soberdrink.c and soberfuncs.c - examples for course 07

[previous example] [course07] [Table of contents] [next example]
/* Filename      : soberdrink.c
 * Description   : a special drink messing around with your money and exp
 *
 * written       : 03-10-1996 - Gunner
 * last modified : 27-05-1998 - Gunner
 * HTML-Version  : 04-02-2000 - Ghorwin
 */

#include <mudlib.h>
inherit I_DRINK;

#define FUNC "/doc/crashcourse/course07/soberfuncs"

create()
{
    ::create();
    set_name("magical drink");
    add_id(({"drink","magic drink"}));
    set_short("A magical drink");
    set_long("The drink seems to have some magical properties. But, what "
        "it could do to you, is unknown...\n");
    set_weight(1);
    set_value(1000);
    set_heal(0);
    set_strength(0);
    set_info("The drink makes you sober/unsoaked, but drains exp and money.\n");

    add_property(({"hidden","magic"}));
    add_hook("__drink",(:call_other,FUNC,"drink_sober":));
    replace_program(I_DRINK);
}

soberfuncs.c


/* Filename      : soberfuncs.c
 * Description   : the functionfile for soberdrink.c
 *
 * written       : 03-10-1996 - Gunner
 * last modified : 27-05-1998 - Gunner
 * HTML-Version  : 04-02-2000 - Ghorwin
 */

#include <mudlib.h>
#include "/doc/crashcourse/defs.h"
inherit I_DAEMON;

/* 
 * drink_sober : Called by the __drink hook in soberdrink.c
 */
void
drink_sober()
{
    tell_object(TP,"The drink tastes refreshing... But, what did it do?\n");
    if (TP->query_money() <= 0) 
        return;     // Heheh.. Nothing happened...

    if (TP->query_money() > 5000)
        TP->add_money(-5000);
    else
        TP->add_money(-TP->query_money());

    if (TP->query_exp() > 5000)
        TP->add_exp(-5000);
    else
        TP->add_exp(-TP->query_exp());

    TP->add_intoxication(-TP->query_intoxication());
    TP->add_soaked(-TP->query_soaked());
}