biggnome.c, smallgnome.c and gnomefuncs.c - examples for course 08

[previous example] [course08] [Table of contents] [next example]
/* Filename      : biggnome.c
 * Description   : an big unfriendly gnome
 *
 * written       : 04-10-1996 - Gunner
 * last modified : 28-05-1998 - Gunner
 * HTML-Version  : 04-02-2000 - Ghorwin
 */

#include <mudlib.h>
inherit I_MONSTER;

#define FUNC "/doc/crashcourse/course08/gnomefuncs"

create()
{
    ::create();
    set_name("Big gnome");
    add_id(({"gnome","really big gnome"}));
    set_short("A big gnome");
    set_long("This is one big gnome. He's really big.\n");
    set_level(20);
    set_race("gnome");
    load_chat(20,({"The big gnome says: Tiny!\n",
        "The big gnome says: Pissant!\n",
        "The big gnome says: Turd!\n"}));
    add_hook("__catch_tell",({FUNC,"catch_biggnome"}),this_object());
    replace_program(I_MONSTER);
}

smallgnome.c


/* Filename      : smallgnome.c
 * Description   : an small unfriendly gnome
 *
 * written       : 04-10-1996 - Gunner
 * last modified : 28-05-1998 - Gunner
 * HTML-Version  : 04-02-2000 - Ghorwin
 */

#include <mudlib.h>
inherit I_MONSTER;

#define FUNC "/doc/crashcourse/course08/gnomefuncs"

create()
{
    ::create();
    set_name("Small gnome");
    add_id(({"gnome","really small gnome"}));
    set_short("A small gnome");
    set_long("This is one small gnome. He's really small.\n");
    set_level(2);
    set_race("gnome");
    load_chat(20,({"The small gnome says: Turkey!\n",
        "The small gnome says: Goofball!\n",
        "The small gnome says: Goon!\n"}));
    add_hook("__catch_tell",({FUNC,"catch_smallgnome"}),this_object());
    replace_program(I_MONSTER);
}

gnomefuncs.c


/* Filename      : gnomefuncs.c
 * Description   : functionfile for gnomes
 *
 * written       : 04-10-1996 - Gunner
 * last modified : 28-05-1998 - Gunner
 * HTML-Version  : 04-02-2000 - Ghorwin
 */

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

/* 
 * catch_biggnome : The big gnome receives a message
 */
void
catch_biggnome(object gnome, string message)
{
    string insult, tell;

    // Delete the last '\n' from the message, if any
    if (message[-1..-1] == "\n") 
        message = message[0..strlen(message)-2];

    if (sscanf(message,"The small gnome says: %s",insult) != 1)
        return;     // Nothing happens...

    tell = "The big gnome thunders: What? Who are you calling "
        "a " + insult + "?!?\n";

    call_out("send_message",2,ENV(gnome),tell);
}

/* 
 * catch_smallgnome : The small gnome receives a message
 */
void
catch_smallgnome(object gnome, string message)
{
    string insult, tell;

    // Delete the last '\n' from the message, if any
    if (message[-1..-1] == "\n") 
        message = message[0..strlen(message)-2];

    if (sscanf(message,"The big gnome says: %s",insult) != 1)
        return;     // Nothing happens...

    tell = "The small gnome wimpers: Hey! Why are you hacking "
        "on me? I'm not a " + insult + "\n";

    call_out("send_message",2,ENV(gnome),tell);
}

/* 
 * send_message : Delay the reply so it won't get before the insult. ;-)
 */
void
send_message(object room, string message)
{
    if (room)
        tell_room(room,message);
}