Ejemplo n.º 1
0
void main(int argc, string argv[])
{
  string type, name;

  initparam(argv, defv);
  type = getparam("type");
  name = getparam("name");
  printf("type_length(\"%s\") = %d\n", type, type_length(type));
  printf("type_name(\"%s\") = %s\n", type, type_name(type));
  printf("type_base(\"%s\") = %s\n", type, type_base(type));
  printf("type_fmt(\"%s\", TRUE) = %s\n", type, type_fmt(type, TRUE));
  printf("type_fmt(\"%s\", FALSE) = %s\n", type, type_fmt(type, FALSE));
  printf("name_type(\"%s\") = %s\n", name, name_type(name));
}
Ejemplo n.º 2
0
static int
listopt_handler (parse_ctx_t pctx, void *vctx, int togidx, lextype_t dtype, name_t *togname)
{
    lstgctx_t ctx = vctx;
    int set_on = (name_type(togname) == LEXTYPE_NAME_TOGGLE_ON);

    ctx->cur_state->listopts[togidx] = set_on;
    // If we aren't putting source in the listing, tell
    // the logging module to print the source line
    if (togidx == LISTOPT_SRC) {
        log_logsrctolst_set(parser_logctx(pctx), !set_on);
    }
    return 1;

} /* listopt_handler */
Ejemplo n.º 3
0
void
inventory(struct linked_list *container, int type)
{
    int cnt;

    if (type == 0)
    {
        msg("What kind of item <%s> to inventory (* for all)?",  type_list);

        type = readchar();

        if (type == ESCAPE)
        {
            after = FALSE;
            msg("");
            return;
        }
    }

    /*
     * Get a list of items to print out. If the user selects '*', list
     * them all.
     */

    if (type == '*')
        type = 0;   /* no type passed ->use them all */

    mpos = 0;

    if ((cnt = count_bag(container, type, NULL)) == 0)
        msg("You don't have any %s.", name_type(type));
    else
    {
        apply_to_bag(container, type, NULL, baf_print_item, &type);
        end_line();
        msg("");
    }

    return;
}
Ejemplo n.º 4
0
struct object *
get_object(struct linked_list *container, char *purpose, int type, int (*bff_p)(struct object *obj, bag_arg *junk))
/* char    *container;    what container has what we want               */
/* char    *purpose;      a message (verb) to print if we cant find any */
/* char    type;          type (o_type) to pick out (NULL = any)        */
/* int     (*bff_p) ();   bag filter function to test item              */
{
    struct object   *obj_p = NULL;
    char sel_id;   /* selected type and id */
    int  sel_type;
    char response;

    if (container == NULL)
    {
        msg("There isn't anything in there.");
        after = FALSE;
        return(NULL);
    }

    /* Make sure we have at least one item that qualifies! */

    if (apply_to_bag(container, type, bff_p, NULL, NULL) == NULL)
    {
        msg("You seem to have nothing to %s.", purpose);
        after = FALSE;
        return(NULL);
    }

    while (obj_p == NULL)
    {
        if (type == 0)
        {
            msg("What kind of item <%s> do you want to %s (* for list)?", type_list, purpose);

            response = readchar();
            ESCAPE_EXIT(response);
            msg("");

            if (response == '*')
            {
                add_line("! Potion");
                add_line("? Scroll");
                add_line("= Ring");
                add_line("/ Stick");
                add_line("] Armor");
                add_line(") Weapon");
                add_line(": Food");
                end_line();
                continue;
            }


            if (!is_member(type_list, response)) {
                beep();
                continue;
            }


            if (count_bag(container, response, NULL) == 0)
            {
                msg("You don't have any %s.", name_type(response));
                continue;
            }

            type = response;
        }

        while(obj_p == NULL)
        {
            msg("What item do you want to %s (* for list)?", purpose);
            response = readchar();
            msg("");
            ESCAPE_EXIT(response);

            if (response == '*')
            {
                mpos = 0;
                apply_to_bag(container, type, bff_p, baf_print_item, &type);
                end_line();
                continue;
            }

            sel_type = type;
            sel_id = response;

            obj_p = scan_bag(container, sel_type,unprint_id(&sel_id));
        }
    }

    mpos = 0;
    msg("");
    return(obj_p);
}
Ejemplo n.º 5
0
int
add_pack(struct linked_list *item, int print_message)
{
    struct object   *obj, *op;
    int from_floor;

    if (item == NULL)
    {
        from_floor = TRUE;

        if ((item = find_obj(hero.y, hero.x)) == NULL)
        {
            msg("Nothing to pick up.");
            return(FALSE);
        }
    }
    else
        from_floor = FALSE;

    if (from_floor)
    {
        item = get_stack(item);

        if (!item)
            return(FALSE);
    }

    obj = OBJPTR(item);

    /* If it is gold, just add its value to rogue's purse and get rid of */

    if (obj->o_type == GOLD)
    {
        struct linked_list  *mitem;
        struct thing    *tp;

        if (print_message)
        {
            if (!terse)
                addmsg("You found ");

            msg("%d gold pieces.", obj->o_count);
        }

        /*
         * First make sure no greedy monster is after this gold. If
         * so, make the monster run after the rogue instead.
         */

        for (mitem = mlist; mitem != NULL; mitem = next(mitem))
        {
            tp = THINGPTR(mitem);

            if (tp->t_horde==obj)
            {
                tp->t_ischasing = TRUE;
                tp->t_chasee = &player;
                tp->t_horde  = NULL;
            }
        }

        /*
         * This will cause problems if people are able to drop and
         * pick up gold, or when GOLDSTEAL monsters are killed.
         */

        /* Thieves get EXP for gold they pick up */

        if (player.t_ctype == C_THIEF)
        {
            pstats.s_exp += obj->o_count / 4;
            check_level();
        }

        purse += obj->o_count;

        if (from_floor)
            rem_obj(item, TRUE);    /* Remove object from the level */

        return (TRUE);
    }

    /* see if he can carry any more weight */

    if (itemweight(obj) + pstats.s_pack > pstats.s_carry)
    {
        msg("Too much for you to carry.");

        if (print_message)
        {
            msg("%s onto %s", terse ? "Moved" : "You moved",
                inv_name(obj, LOWERCASE));
        }

        return(FALSE);
    }

    /*
     * Link it into the pack. If the item can be grouped, try to find its
     * neighbors and bump the count. A special case is food, which can't
     * be grouped, but an exact match allows the count to get
     * incremented.
     */

    if ((op = apply_to_bag(pack, obj->o_type, bff_group, NULL, obj)) != NULL)
    {
        op->o_count += obj->o_count;    /* add it to the rest */

        if (from_floor)
            rem_obj(item, FALSE);

        pack_report(op, print_message, "You now have ");

        return(TRUE);
    }

    /* Check for and deal with scare monster scrolls */

    if (obj->o_type == SCROLL && obj->o_which == S_SCARE)
        if (obj->o_flags & ISCURSED)
        {
            msg("The scroll turns to dust as you pick it up.");
            rem_obj(item, TRUE);
            return(TRUE);
        }

    /* Check if there is room */

    if (count_bag(pack, obj->o_type, NULL) == max_print())
    {
        msg("You have no room for more %s.", name_type(obj->o_type));

        if (print_message)
        {
            obj = OBJPTR(item);
            msg("%s onto %s.", terse ? "Moved" : "You moved",
                inv_name(obj, LOWERCASE));
        }

        return(FALSE);
    }

    /*
     * finally, add the new item to the bag, and free up the linked list
     * on top of it.
     */

    if (from_floor)
        rem_obj(item, FALSE);

    push_bag(&pack, obj);
    pack_report(obj, print_message, "You now have ");
    ur_free(item);

    return(TRUE);      /* signal success */
}