treebranch.c and treefuncs.c - examples for course 05

[previous example] [course05] [Table of contents] [next example]
/* Filename      : treebranch.c
 * Description   : on a tree branch with a birdnest
 *
 * written       : 02-10-1996 - Gunner
 * last modified : 26-05-1998 - Gunner
 * HTML-Version  : 02-02-2000 - Ghorwin
 */

#include <mudlib.h>
inherit I_ROOM;

#define FUNC "/doc/crashcourse/course05/treefuncs"

create()
{
    ::create();
    set_light(1);
    set_short("On a tree branch");
    set_long("You are standing on a tree branch high up in one of the "
        "trees. The sun is shining high above you as you look "
        "a birdnest right in front of you.\n");

    add_item(({"tree","trees","forest","dark forest","gloomy forest"}),
        "The dark forest is below you. And, hopefully it'll "
        "stay there.\n");
    add_item(({"branch","tree branch"}),"There's a birdnest on the "
        "branch.\n");
    add_item(({"sky","sun","cloud","clouds"}),"The sun is shining high "
        "above you on the sky. There's not a cloud to be seen.\n");
    add_item(({"ground","soft ground"}),"You can't see the ground "
        "from up here.\n");
    add_item(({"nest","birdnest","empty nest","empty birdnest"}),
        "The nest seems to be empty.\n");
    add_neg(({"get","take"}),({"nest","birdnest","empty nest","empty birdnest"}),
        "Better leave it alone. It seems to fastened to the branch.\n");

    add_trigger("climb",(:call_other,FUNC,"climb_down",this_object():));
    add_trigger("search",(:call_other,FUNC,"search_nest",this_object():));

    add_hook("__reset",(:call_other,FUNC,"reset_tree",this_object():));

    replace_program(I_ROOM);
}


treefuncs.c


/* Filename      : treefuncs.c
 * Description   : the functionfile for treebranch.c
 *
 * written       : 02-10-1996 - Gunner
 * last modified : 05-11-1997 - Gunner
 * HTML-Version  : 02-02-2000 - Ghorwin
 */

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

#define FOREST "/doc/crashcourse/course05/forest"
#define RING "/doc/crashcourse/course05/ring"

/* 
 * reset_tree : Clear up the room for this next reset
 */
void
reset_tree(object room)
{
    room->remove_property("searched_nest");
}

/*
 * climb_down : Let's try to get down in one piece, shall we?
 */
int
climb_down(object room, string arg)
{
    object dest_room = load_object(FOREST);

    if (!arg || (arg != "down" && arg != "tree"))
        return notify_fail("Climb where?\n");

    tell_object(TP,"You carefully climb down.\n");
    tell_room(room,TP->query_name() + " climbs down the tree.\n",({TP}));
    tell_room(dest_room,TP->query_name() + " comes down the tree.\n",({TP}));
    TP->move_player("climbing down",dest_room);
    return 1;
}

/* 
 * search_nest : Let's see if we can't find a treasure inside the nest...
 */
int
search_nest(object room, string arg)
{
    object ring;

    if (!arg || (arg != "nest" && arg != "birdnest"))
        return notify_fail("Search what?\n");

    if (room->query_property("searched_nest"))
    {
        tell_object(TP,"You find nothing.\n");
        return 1;
    }

    tell_object(TP,"You search the nest and find a ring!\n");
    tell_room(room,TP->query_name() + " searches the nest and picks up "
        "a ring!\n",({TP}));
    ring = clone_object(RING);
    ring->move(TP);
    room->add_property("searched_nest");
    return 1;
}