I want to add a limiter to examine. IE. examine portal weapon .. would return all the weapons the portal contains, not all the items. I thought I saw a snippet for this at one time, but it eludes me now if it is out there. So I looked at do_examine, and it triggers do_look quite a bit throughout it, but I don't understand what causes the triggers, or what effects they have on do_examine. Anyways if someone could explain to me how the items in the portal are stored. And maybe what part of the code calls on them, to display them to the character. I would be grateful.
I took a quick glance at an old smaug to refresh my memory. (it's heavily modified but should still be close enough)
In do_examine (act_info.c), there is a switch for item types. This calls do_look for containers. do_look however calls show_list_to_char to display it's contents.
How I would handle something like this is to make a series of functions that return true/false when passed an object. I would then make a copy of show_list_to_char that accepts a function pointer as an argument. If that pointer is not null, then you pass the object to it, and based on the result, you can filter objects from the output. Once this works properly, I'd probably replace the existing show_list_to_char with a macro that calls the new one without a filter.
Anyway, from here it's a simple matter of determining what filter to pass to the show function. You may need to modify the specific case in do_examine to call show_list_to_char directly.
How SMAUG stores objects in containers is with a linked list, that is, the obj_data struct has these 4 members: OBJ_DATA *next_content; OBJ_DATA *prev_content; OBJ_DATA *first_content; OBJ_DATA *last_content;
first_content represents the first object stored in the list, last_content is the last one. next_content/prev_content point at the next/previous object in the list. There are numerous examples in the code similar to: for (obj = cont->first_content; obj; obj=obj->next_content) This shows how to use a for loop to iterate through a list.
On a side note, I've written some code for C++ modified SmaugFUSS to do this, it comes in 2 forms. One which returns the first unfiltered object it finds, and one that takes a std::list as input and adds each unfiltered object to this list. This is based on how I handled local searches in java.