adonthell-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Adonthell-devel] item equality


From: Kai Sterker
Subject: [Adonthell-devel] item equality
Date: Wed, 29 Jan 2003 18:26:49 +0100

That would have been a mail about inventories, but then it occured to me
that I cannot really dive into inventories without being able to compare
items for equality.

The reason is the following: imagine you pick up a stackable item. What
you expect is that it gets added to an already existing stack. I.e. if
you pick up a coin, it should be added to the coins you already have,
not to an empty slot.

The question is, how does the inventory figure out whether an item you
pick up fits to an existing stack? It's simple with coins. But imagine
torches were stackable. You could have a torch that is half-burnt in
your inventory, and you pick up a new one. Should they be stacked?
Possibly not, because stacking means something like increasing a counter
that comes with each slot. After all, if a character carries 1000 coins,
that shouldn't be 1000 individual items! Instead it should be one item
with count 1000.

With the torches however, that does not work: we neither have 2 new
torches nor 2 half-burnt ones. Same would be true for potions that are
half-empty, runes that are partly discharged, etc.

The solution to that problem is the following: a stack requires items to
be equal in *all* their attributes. Because a stack is just one item and
a counter. But a slot may contain different stacks, as long as the items
are "roughly" equal. I.e of same kind but with different attributes.


So much in advance. The actual issue of that mail is equality. How do we
tell whether items are exactly respectively roughly equal?

Roughly equal seems to be easier, so lets cover that first. Is it
reasonable to assume that items with equal name are at least "roughly
equal"? I can't think of any example where this wouldn't be the case.
Any thoughts on this?


Exactly equal. That is the case if all item properties are exactly
equal. But item designers shouldn't be forced to write an "equals"
method for each item that compares all attributes of two items. Not only
because this is more work, but also because it is quite a costly
operation. 

So I thought that we could perhaps create a hash of an item's
properties. That together with the item name should help to check
whether items are equal or not. The hash could even be saved with the
item, so it only has to be regenerated when a change is made to an item,
which shouldn't happen too often.

Of course, all of this should be as automated as possible!

Any ideas on this are welcome. Here's what thoughts I had so far:

* Python provides the md5 module, which would be perfect for generating
  good hashes.

* The __setattr__ method allows us to intercept write access to
  attributes. Good oportunity to trigger a hash-update without any
  further work for item makers. Implementing this method in the item
  base class should suffice.

* Remains figuring out what attributes belong to an item. In the worst
  case, we'd need a little list for each item (which could also be 
  useful for an item editor).

Further thoughts?


That's it. I'll do some further reading on that subject and maybe some
testing too. If anyone got any insights into this matter, please lets
hear it. Otherwise I'll have to see what I can do :).

Kai




reply via email to

[Prev in Thread] Current Thread [Next in Thread]