spy.c and spyfuncs.c - examples for course 09

[previous example] [course09] [Table of contents] [next example]
/* Filename      : spy.c
 * Description   : special item to spy out room messages
 *
 * written       : 05-10-1996 - Gunner
 * last modified : 28-05-1998 - Gunner
 * HTML-Version  : 06-02-2000 - Ghorwin
 */

#include <mudlib.h>
inherit I_ITEM;

#define FUNC "/doc/crashcourse/course09/spyfuncs"

create()
{
    ::create();
    set_name("glassorb");
    add_id(({"glass","orb","spying orb"}));
    set_short("A glassorb");
    set_long("A glassorb used for spying on other people.\n");
    set_weight(1);
    set_value(500+random(500));
    set_info("'send spy to <player/monster>'\n");
  
    add_trigger("send",(:call_other,FUNC,"send_spy",this_object():));
    add_property(({"hidden","magic","glass"}));
    replace_program(I_ITEM);
}

spyfuncs.c


/* Filename      : spyfuncs.c
 * Description   : the functionfile for spy.c
 *
 * written       : 05-10-1996 - Gunner
 * last modified : 28-05-1998 - Gunner
 * HTML-Version  : 06-02-2000 - Ghorwin
 */

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

#define TIMEOUT 60*3+random(60*2)

/* 
 * send_spy : Start spying on someone...
 */
int
send_spy(object orb, string arg)
{
    string name;
    object spy, who, room;

    if (!arg || sscanf(lower_case(arg),"spy to %s",name) != 1)
        NOT_FAIL("Send spy to whom?\n");

    who = find_living(name);

    if (!who)
        NOT_FAIL("Can't find " + name + " anywhere.\n");

    room = ENV(who);
    if (!room)
        NOT_FAIL("No room found.\n");

    if (Q_NOMAGIC(room) || Q_NOTELEIN(room))
        NOT_FAIL("The globe fails you.\n");

    spy = clone_object(I_MONSTER);
    spy->add_hook("__catch_tell",({TO, "spy_tells"}),spy);
    spy->invis();
    spy->add_property("spy_owner",TP);
    spy->add_property("no_fight");

    tell_room(room,"You notice a brief shimmering in the air.\n");

    spy->move(room);

    call_out("remove_spy",TIMEOUT,spy);

    tell_object(TP,"The globe vanishes without a trace.\n");
    orb->destroy();
    return 1;
}


/* 
 * spy_tells : Send the spy messages to the player
 */
void
spy_tells(object spy, string message)
{
    object owner = spy->query_property("spy_owner");
    if (!owner)
    {
        spy->destroy();
        return;
    }
    message = C_BOLD + "[SPY] " + C_END + message;
    tell_object(owner, message);
}

/* 
 * remove_spy : Time to remove the spy
 */
void
remove_spy(object spy)
{
    object owner;

    if (!spy) return;
    owner = spy->query_property("spy_owner");

    if (owner)
        tell_object(owner,"Your spy suddenly stops sending you information.\n");

    spy->destroy();
}