Considerate Holdall

version 9 by Jon Ingold

  • Home page
  • Beginning
  • Previous



  • section 3 - the main loop

    The considered holdall is a thing that varies. The current stashable thing is a thing that varies.

    This is the considerate player's holdall rule:
    [ if you've got too much in your hands...]
    if the number of things carried by the player is at least the carrying capacity of the player begin;
        now every player's holdall is CHunavailable;
        repeat with current holdall running through player's holdalls enclosed by the player begin;
    [ mark-up holdalls to see if they're appropriate to use...]
            follow the holdall rules for the current holdall;
            if the outcome of the rulebook is the disallow stashing outcome, now the current holdall is CHunavailable;
            if the outcome of the rulebook is the allow stashing outcome, now the current holdall is CHavailable;
        end repeat;
        repeat with current holdall running through CHavailable player's holdalls begin;
    [ try each holdall individually... hopefully we won't actually have to try very many! ]
            change considered holdall to current holdall;
            repeat with item running through things carried by the player begin;
    [ see if we can stash items in this particular holdalll... ]
                follow the stashing rules for the item;
                if the outcome of the rulebook is the disallow stashing outcome, now the item is CHunviable;
                if the outcome of the rulebook is the allow stashing outcome, now the item is CHviable;
            end repeat;
            change the current stashable thing to a random forgotten-about CHviable thing held by the player;
    [ is there anything you could stash which you've never used...? ]
            if the current stashable thing is not a thing begin;
    [ if not, find the oldest thing we can stash ... ]
                repeat through Table of Recent Items in time order begin;
                    if the recent item entry is CHviable and the recent item entry is carried by the player begin;
                        change the current stashable thing to the recent item entry;
    [ we're happy with this item .]
                        break;
                    end if;
                end repeat;
            end if;
            if the current stashable thing is a thing begin;
    [ we're happy with the combination of stashable thing and holdall... ]
                if using the inline implicit library option begin;
    [ this is an entry point for implicit libraries, such as Eric Eve's, to use, to tidy up more complicated lines. ]
                    spit inline library message as appropriate for the current stashable thing into the considered holdall;
                    if the current stashable thing is not inside the considered holdall, stop the action;
                otherwise;
    [ try putting it away, and report if we managed to ... ]
                    try silently inserting the current stashable thing into the considered holdall;
                    if the current stashable thing is not inside the considered holdall, stop the action;
                    spit library message as appropriate for the current stashable thing into the considered holdall;
                end if;
                continue the action;
            end if;
        end repeat;
    [ we give up! ]
        spit library message for failure of holdalls instead;
    end if;



    To spit library message for failure of holdalls:
        (- GL__M(##Take,12);
        -)

    To spit inline library message as appropriate for (n - a thing) into (s - a thing):
        (- SACK_OBJECT = {s}; #ifdef INLINE; __stash({n}); #endif;
        -)

    To spit library message as appropriate for (n - a thing) into (s - a thing):
        (- SACK_OBJECT = {s}; GL__M(##Take,13,{n});
        -)

    Include (- Constant CONSIDERATE_HOLDALL; -).

    Considerate Holdall ends here.