[Top][All Lists]

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

Re: [Adonthell-devel] Adjustments to items.h ?

From: Kai Sterker
Subject: Re: [Adonthell-devel] Adjustments to items.h ?
Date: Thu, 14 Feb 2002 13:16:35 +0100 (CET)

On 14 Feb 2002 10:32:16 +0100 Alexandre Courbot wrote

> What I've been thinking about is HOW do items act. An heal potion gives
> heal points, a sword hits, a rune can be combined with a weapon to
> influence it's action, etc... Items should be easy to design, and their
> actions certainly not hard-coded in C++. You guessed it, our old pal
> Python would help here once again.

Well, I too would say that the more advanced item mechanics would involve
Python. As would parts of the combat system, like the moves.

Keeping that in mind is a good thing, but I think the basics (and we're
talking basics at the moment) wouldn't involve Python as such. As any
other part of the engine, items would have a Python shadow class, but no
> The idea is that each item (no matter whether it's a weapon, a yeti
> figurine, or something else) is defined (at least partly) by a Python
> class that allows it to do certain things lets say for example a heal
> potion:

Since we're already talking about this topic: I had done that in a 
different way. 
Instead of defining classes for each type of items, I would rather define
classes for 'actions'. Like 'consume', 'combine', 'drop', 'equip', and so

As a list of parameters, they'd get the attributes they affect, or the
valid 'recipies' in case of a combination.

That would mean that item or character attributes are stored in a map,
not as simple ints, so they can be accessed by name.

Then the consume class might look like

class consume:
    # two lists of strings, telling which character attributes are changed
    # by which item modifiers
    def  __init__ (list_of_attributes, list_of_modifiers):
        # ...

    def apply (attribute, modifier):
        val = self.character.get_val (attribute) + self.item.get_val (modifier)
        self.character.set_val (attribute, val)

    def use (character, item):
        self.character = character
        self.item = item
        # calls the apply method for corresponding items of both lists
        # Yep, python rocks ;)        
        map (self.apply, self.list_of_attributes, self.list_of_modifiers)

That way, you had one consume script that works for all potions that
affects certain attributes. Maybe, you could even keep the attributes
affected with the individual potions (or foodstuffs), then you would need
only one consume script at all.

> The consequence is that all 'passeables' objects need to inherit from a
> class that contains at least a 'type' member so we can guess which kind
> of object it is when we pass it to a Python function.

Sure, that is a necessity.

Anyway, right now we're doing basic stuff, so it might be a bit early to
get too detailed on the subject of using items and such.


reply via email to

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