com/sacrifice.c and help/sacrifice - examples for course 13

[previous example] [course 13] [Table of contents] [next example]
/* Filename      : sacrifice.c
 * Description   : the guild spell 'sacrifice'
 *
 * written       : 30-05-1998 - Gunner
 * last modified : 31-05-1998 - Gunner
 * HTML-Version  : 13-02-2000 - Ghorwin
 */

#include "/doc/crashcourse/course13/include/guild.h"
#include "/doc/crashcourse/course13/include/spells.h"
inherit I_COMMAND;

string
query_action()
{
    return "sacrifice";
}

string
short_help()
{
    return "Sacrifice corpses in order to gain more dark powers.\n";
}

string
help()
{
    return GUILD_HELPDIR + "sacrifice";
}

int
sacrifice_corpse(object corpse)
{
    int corpses;
    object ob, env = environment(corpse);

    foreach(ob in all_inventory(corpse))
    {
        ob->move(env);
        if (ob->query_property("corpse"))
            corpses += sacrifice_corpse(ob);
    }

    corpses++;

    TP->reduce_spell_point(-3-random(4)); // 3-6 extra spell points per corpse

    corpse->destroy();

    return corpses;
}

// General function that works somewhat like present(), except instead of
// just returning the first match, it returns all of them.
// Can be very handy...

object *
all_objects(string name, object room)
{
    object ob, *objs = ({ });

    if (!room || !name) return ({ });

    foreach(ob in all_inventory(room))
        if (ob->query_id(name) || ob->query_property(name))
            objs += ({ ob });

    return objs;
}

static int
main(string arg)
{
    object ob, room, *corpses;
    int corps;

    if (arg) arg = lower_case(arg);

    if (!arg || (arg != "corpse" && arg != "corpses"))
        NOT_FAIL("Sacrifice what?\n");

    room = environment(TP);

    if (!room)
        FAIL("Error! No ENV! CONTACT MAINTAINER!\n") // Should not happen

    CHECK_SPECIAL(room);
    CHECK_MAGIC(room);
    CHECK_BUSY(TP);

    corpses = all_objects("corpse",room);

    if (sizeof(corpses) <= 0)
        FAIL("There is no corpse here to sacrifice.\n")

    if (arg == "corpse") // Player only wants to sacrifice the first corpse.
    {
        corps = sacrifice_corpse(corpses[0]);
        if (corps > 1)
        {
            write("As you sacrifice the corpses, you feel stronger.\n");
            tell_room(room,Q_NAME(TP) + " sacrifices some corpses.\n", ({TP}));
        }
        else
        {
            write("As you sacrifice the corpse, you feel stronger.\n");
            tell_room(room,Q_NAME(TP) + " sacrifice a corpse.\n", ({TP}));
        }
        return 1;
    }

    foreach(ob in corpses)
        corps += sacrifice_corpse(ob);

    if (!corps)
        FAIL("There is no corpse here to sacrifice!\n")

    if (corps == 1)
    {
        write("As you sacrifice the corpses, you feel stronger.\n");
        tell_room(room,Q_NAME(TP) + " sacrifices some corpses.\n", ({TP}));
    }
    else
    {
        write("As you sacrifice the corpse, you feel stronger.\n");
        tell_room(room,Q_NAME(TP) + " sacrifice a corpse.\n", ({TP}));
    }
    return 1;
}

help/sacrifice


		~~     SACRIFICE     ~~

DESCRIPTION:

Sacrifice your fallen enemies to the gods of darkness. In exchange
they will grant you more power to destroy even more of your enemies.

		~~     SACRIFICE     ~~