It might be better not to mess with the actual inventory, but to just hide the underwear when they’re worn under the jeans, something like this:
First, let’s define a clothing kind and a many-to-many relation on it. We could just define the relation on all things, but that would be kind of inefficient.
[code]The Dressing Room is a room. The player wears some tattered underwear. The player wears a pair of jeans.
Clothing is a kind of thing. Clothing is usually wearable. The jeans and the underwear are clothing.
Coverage relates various clothing to various clothing. The verb to cover (it covers, they cover, it covered, it is covered, it is covering) implies the coverage relation.
The jeans cover the underwear.
[/code]
Next, we’ll add a rule saying that covered clothing counts as concealed. If we wanted to be really fancy, we could use pathfinding to make the relation automatically transitive (so that e.g. if a jacket covered a sweater and the sweater covered a T-shirt, then the jacket would automatically cover the T-shirt), but that would be slower and more complicated, and probably not worth it unless you had a huge variety of clothing (in which case you should look into implementing something more modular anyway, like standardized clothing slots).
Rule for deciding the concealed possessions of somebody (called the person):
if the particular possession is clothing and the person wears the particular possession and the person wears something that covers the particular possession, yes;
otherwise make no decision.
Finally, we need to reimplement the inventory-taking rule to make it skip concealed clothing – the normal inventory command assumes that the player knows their possessions whether or not they’re concealed from others.
[code]The print standard inventory rule is not listed in any rulebook.
Carry out taking inventory (this is the print unconcealed inventory rule):
say “You are carrying: [line break]”;
now all things enclosed by the player are marked for listing;
now all concealed things worn by the player are unmarked for listing;
list the contents of the player, with newlines, indented, giving inventory information, including contents, with extra indentation, listing marked items only.
Test me with “i / remove jeans / i / remove underwear / i / wear jeans / i / remove jeans / drop all / i”.
[/code]
Note that the effect might be less confusing if we modified the inventory to list carried and worn items separately – see e.g. Chapter 6.7. (Inventory) in the Inform Recipe Book, on which the rule above is based.
All this might seem overkill for just two items of clothing, but this way it’s easy to add more of them:
The ratty T-shirt, the green sweater, the leather jacket, the swirling opera cloak, the pair of plaid socks and the pair of expensive sneakers are clothing in the dressing room. The sweater covers the T-shirt. The jacket covers the T-shirt and the sweater. The cloak covers the T-shirt, the sweater, the jacket, the underwear and the jeans. The sneakers cover the socks. Understand "shirt" as the T-shirt. Understand "shoes" as the sneakers.